Skip to content

Commit 41a6b9a

Browse files
authored
Merge pull request #1204 from TOMToolkit/fix/docs_for_async
fix some docs things
2 parents 8efc6a3 + c1bac25 commit 41a6b9a

2 files changed

Lines changed: 29 additions & 20 deletions

File tree

docs/code/backgroundtasks.rst

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ In this tutorial, we will go over how to run tasks asynchronously in
5454
your TOM if you have the need to do so.
5555

5656
Running tasks with django-tasks
57-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
58-
`django-tasks <https://github.com/django/deps/blob/a83080652411e34e6afa8e1f0a97b675a76358e5/accepted/0014-background-workers.rst>`
57+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58+
`django-tasks <https://github.com/django/deps/blob/a83080652411e34e6afa8e1f0a97b675a76358e5/accepted/0014-background-workers.rst>`__
5959
is a reference implementation of Django’s official background tasks library.
6060
It provides an interface for marking functions as tasks and a worker
6161
for executing them. The database backend utilizes the Django ORM,
@@ -66,7 +66,9 @@ Setting up django-tasks in a TOM
6666
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6767
Check to make sure your TOM has django_tasks installed:
6868

69-
.. code:: python
69+
.. code-block:: python
70+
:caption: settings.py
71+
7072
INSTALLED_APPS = [
7173
...
7274
'django_tasks',
@@ -78,7 +80,9 @@ By default, the immediate mode is enabled which means tasks are not run
7880
asynchronously. To enable asynchronous execution, you need to configure
7981
the django_tasks to use a the database backend:
8082

81-
.. code:: python
83+
.. code-block:: python
84+
:caption: settings.py
85+
8286
TASKS = {
8387
"default": {
8488
"BACKEND": "django_tasks.backends.database.DatabaseBackend"
@@ -119,22 +123,24 @@ you can do so with:
119123

120124
In ``tasks.py``:
121125

122-
.. code:: python
126+
.. code-block:: python
127+
:caption: mytom/myapp/tasks.py
128+
:linenos:
123129
124-
from django_tasks import task
125-
import time
126-
import logging
130+
from django_tasks import task
131+
import time
132+
import logging
127133
128-
logger = logging.getLogger(__name__)
134+
logger = logging.getLogger(__name__)
129135
130136
131-
@task
132-
def super_complicated_task():
133-
logger.info('starting task...')
134-
time.sleep(2)
135-
logger.info('still running...')
136-
time.sleep(2)
137-
logger.info('done!')
137+
@task
138+
def super_complicated_task():
139+
logger.info('starting task...')
140+
time.sleep(2)
141+
logger.info('still running...')
142+
time.sleep(2)
143+
logger.info('done!')
138144
139145
This task will emulate a function that blocks for 4 seconds, in practice
140146
this would be a network call or some kind of heavy processing task.
@@ -164,15 +170,15 @@ shell!) you should see the following output:
164170
done!
165171
Task id=f323fdc8-4088-424d-a4d4-74ad741c5c04 path=tom_async_demo.views.super_complicated_task state=SUCCEEDED
166172

167-
Notice how calling the enqueue() function returned immediately in the shell, but the
173+
Notice how calling the ``enqueue()`` function returned immediately in the shell, but the
168174
task took a few seconds to complete. This is how it would work in
169175
practice in your django app: Somewhere in your code, for example in your
170176
app’s ``views.py``, you would import the task just like we did in the
171177
terminal. Now when the view gets called, the task will be queued for
172178
execution and the response can be sent back to the user’s browser right
173179
away. The task will finish in the background.
174180

175-
A few more things about the enqueue() function: First, if your task function
181+
A few more things about the ``enqueue()`` function: First, if your task function
176182
takes any arguments, you pass them into the enqueue function. Secondly,
177183
the object returned from this function is a TaskResult. This object can be used to
178184
check the status of the task, retrieve its result, or cancel it.

tom_alerts/brokers/tns.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,12 @@ def fetch_tns_transients(cls, parameters):
170170
Args:
171171
parameters: dictionary containing days_ago (str), min_date (str)
172172
and either:
173-
- Right Ascention, declination (can be deg, deg or h:m:s, d:m:s) of the target,
173+
174+
- Right Ascention, declination (can be deg, deg or h:m:s, d:m:s) of the target,
174175
and search radius and search radius unit ("arcmin", "arcsec", or "deg"), or
175-
- TNS name without the prefix (eg. 2024aa instead of AT2024aa)
176+
177+
- TNS name without the prefix (eg. 2024aa instead of AT2024aa)
178+
176179
Returns:
177180
json containing response from TNS including TNS name and prefix.
178181
"""

0 commit comments

Comments
 (0)