Skip to content

Commit 48cfb55

Browse files
authored
Merge pull request #57 from octue/update-tasks-docs
2 parents b6c2898 + 7ad314b commit 48cfb55

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

docs/source/tasks_usage.rst

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,44 @@
33
Creating and using tasks
44
========================
55

6-
TODO: I've written SO MUCH already and need to get this into production. This week.
6+
Creating tasks
7+
--------------
8+
A task is created by subclassing one of the ``OnDemandTask``, ``PeriodicTask``, or ``SubscriberTask`` classes. In each
9+
task, the ``run`` method must be overridden and any relevant class variables set. See the `full example implementation
10+
here <https://github.com/octue/django-gcp/tree/main/tests/server>`_ to see some example tasks.
711

8-
I'll come back and explain this, I promise.
12+
Registering tasks
13+
-----------------
14+
For tasks to be registered, they must be imported in the app's ``AppConfig.ready`` method. For example, if the classes
15+
are defined in modules in a subpackage of the app called ``tasks``, the app config would look like this:
916

10-
~~ Tom ~~
17+
.. code-block:: python
1118
12-
IN THE MEANTIME:
19+
class ExampleAppConfig(AppConfig):
20+
"""Example (test server) app showing how you would use django-gcp within your own django server"""
1321
14-
Look at management commands available (both in django gcp and the example app), and look at the `full example implementation here <https://github.com/octue/django-gcp/tree/main/tests/server>`_ to pick up how to define and use tasks :)
22+
...
1523
16-
If you need to use this library and can't figure it out, get in touch by raising an issue on GitHub and we'll help you configure your app (and write the docs at the same time).
24+
def ready(self):
25+
# Import the tasks only once the app is ready, in order to register them.
26+
from . import tasks
1727
28+
Note that this requires the task classes to be imported in ``tasks/__init__.py``.
29+
30+
Scheduling periodic tasks
31+
-------------------------
32+
Periodic tasks are triggered by cronjobs in Google Cloud Scheduler. To create these jobs, the ``create_scheduler_jobs``
33+
management command must be run.
34+
35+
Setting up subscriber tasks
36+
---------------------------
37+
Subscriber tasks are triggered by Pub/Sub messages received by subscriptions. To create these subscriptions, the
38+
``create_pubsub_subscriptions`` management command must be run.
39+
40+
More information
41+
----------------
42+
Have a look at the management commands available (both in ``django-gcp`` and the example app). If you are having
43+
problems, get in touch by raising an issue on GitHub and we'll help you configure your app.
1844

1945
Deduplicating tasks
2046
-------------------

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-gcp"
3-
version = "0.11.0"
3+
version = "0.11.1"
44
description = "Utilities to run Django on Google Cloud Platform"
55
authors = ["Tom Clark"]
66
license = "MIT"

0 commit comments

Comments
 (0)