Async Jobs and Scheduling in Django

Ritwick Raj
Jul 21, 2020 · 2 min read

Asynchrony¹ refers to the occurrence of events independent of the main program flow and ways to deal with such events. These may be “outside” events such as the arrival of signals, or actions instigated by a program that take place concurrently with program execution, without the program blocking to wait for results. Asynchronous input/output is an example of the latter cause of asynchrony, and lets programs issue commands to storage or network devices that service these requests while the processor continues executing the program. Doing so provides a degree of parallelism.

Image for post
Image for post

In Django this job can be done by using a few libraries, some of which are:

  • Celery Django
  • ApScheduler
  • Django Q

Having a job in hand to schedule emails, I chose to work with Django Apscheduler for its simplicity and framework friendly environment.

Here are the following steps one has to follow to get the scheduler up and running in Django.

Making Changes in the settings.py

Creating the Scheduler

Triggering the Scheduler to start as soon as Django Server Starts

Adding Jobs to the Scheduler

This is how you add async jobs in Django. When up and running, the django admin would look something like this:

Image for post
Image for post

Happy Reading :)

Ritwick Raj

Written by

What is to be done is to be done!

AnitaB.org Open Source

At AnitaB.org, we envision a future where the people who imagine and build technology mirror the people and societies for whom they build it. We connect, inspire, and guide women in computing, and organizations that view technology innovation as a strategic imperative.

Ritwick Raj

Written by

What is to be done is to be done!

AnitaB.org Open Source

At AnitaB.org, we envision a future where the people who imagine and build technology mirror the people and societies for whom they build it. We connect, inspire, and guide women in computing, and organizations that view technology innovation as a strategic imperative.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store