Job manager for Django Channels
channels_jobmanager
to your INSTALLED_APPS setting:
INSTALLED_APPS = [
...
'channels_jobmanager',
]
JobManager
:
class MyJobs(channels_jobmanager.JobManager):
"""Example job manager class."""
# Allow anonymous user to submit jobs.
allow_anonymous_user = True
# Watch over job state changes.
@classmethod
def on_job_update(cls, job_info):
"""Here we receive job progress messages."""
print('JOB STATE CHANGES:', job_info)
job()
:
@MyJobs.job()
async def my_job(count):
"""Simple counter job."""
for i in range(count):
# Simulate doing the job with sleep.
await asyncio.sleep(delay=1)
# Report progress.
yield {
'message': 'Making a good progress...',
'payload': {'step index': i},
'readiness': (i + 1) / count
}
# Report final result.
yield {
'message': 'Job well done!',
'payload': {'steps made': count},
'readiness': 1.0
}
job_info = my_job(message='Hi!')
my_job.cancel(job_id=job_info.job_id)
python manage.py migrate
python manage.py runserver
python manage.py runworker myjobs
This project is developed and maintained by DATADVANCE LLC. Please
submit an issue if you have any questions or want to suggest an
improvement.
This work is supported by the Russian Foundation for Basic Research
(project No. 15-29-07043).