Management command scheduling options

88 views
Skip to first unread message

Mike Dewhirst

unread,
Oct 23, 2023, 6:09:14 AM10/23/23
to Django users
Django docs suggest cron or Windows scheduler for running management commands.

I would like instead to build an internal Django based scheduler - because after migrating to a new server, setting up the new cron task will be forgotten.

Is there a daily (approximately) event in a Django project I can hook into and test the date?

The task is somewhat database intensive and needs to run quarterly for some users, monthly for most and weekly for others depending on their preferences.

Ideas anyone?

Thanks

Mike

-- 
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Your
email software can handle signing.
OpenPGP_signature.asc

Alessandro Madruga Correia

unread,
Oct 23, 2023, 7:54:26 AM10/23/23
to django...@googlegroups.com
Django-celery 


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7b29b24b-64f0-4f93-9a43-5d8f5e242b57%40dewhirst.com.au.

Rodrigo Bistolfi

unread,
Oct 23, 2023, 8:49:34 AM10/23/23
to django...@googlegroups.com
Use devops for setting up cron jobs as part of the deployment process. You could also use something like https://apscheduler.readthedocs.io/en/3.x/ if you wanna something OS independent.

Ahmedrufai Otuoze

unread,
Oct 23, 2023, 9:11:52 AM10/23/23
to django...@googlegroups.com
Hi Mike,

I've implemented something similar to what you mentioned lately. I used this Python package called APScheduler to schedule and run database intensive queries behind the scene and then cache the result for my users to fetch from making their experience super fast.

The APScheduler can be configured to run at any interval daily, weekly, monthly or any customized interval you require. It's a game changer and a quick win for Windows based OS as they don't support the use of Celery or any other Linux based schedulers without WSL.

Do let me know if you're interested in my implementation, I'm open to show you.

Regards 

Mike Dewhirst

unread,
Oct 23, 2023, 6:42:24 PM10/23/23
to django...@googlegroups.com
On 23/10/2023 11:48 pm, Rodrigo Bistolfi wrote:
Use devops for setting up cron jobs as part of the deployment process.

My requirement is very lightweight and cron would definitely work for me. Both Celery and APScheduler seem like overkill.

How would you ensure the cron job was established on a new server?

Mike

OpenPGP_signature.asc

Mike Dewhirst

unread,
Oct 25, 2023, 5:36:04 AM10/25/23
to django...@googlegroups.com
Ahmedrufai

I looked at APScheduler and like Celery it is too much of a sledgehammer for my tiny problem. 

I ended up using cron to launch the command each day. It works perfectly.

My task now is to find a way to automate establishment of that crontab entry when the project is migrated to a new server.

Cheers

Mike




--
(Unsigned mail from my phone)

Larry Martell

unread,
Oct 25, 2023, 8:26:06 AM10/25/23
to django...@googlegroups.com
On Wed, Oct 25, 2023 at 5:35 AM Mike Dewhirst <mi...@dewhirst.com.au> wrote:
>
> Ahmedrufai
>
> I looked at APScheduler and like Celery it is too much of a sledgehammer for my tiny problem.
>
> I ended up using cron to launch the command each day. It works perfectly.
>
> My task now is to find a way to automate establishment of that crontab entry when the project is migrated to a new server.

How are new servers deployed? How many new servers will be deployed?
If it's a one off thing you are doing manually, you just have to
remember to do it. If there are many, then you should use a tool like
terraform or octopus, or something similar and have that do it.

Adam Stein

unread,
Oct 25, 2023, 8:50:23 AM10/25/23
to django...@googlegroups.com
I use django-crontab myself for cron jobs. That way, I can add or update easily during deployment. Maybe you can make use of that so you can keep everything in your project.

Janet Anastacia

unread,
Oct 25, 2023, 1:15:17 PM10/25/23
to django...@googlegroups.com
I'm new to Django development, I kindly ask for the best free  websites to learn Django for beginners in 2023. I have tried to learn from different websites but I don't seem to grab anything. 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

SUNIL PATEL

unread,
Oct 25, 2023, 1:17:53 PM10/25/23
to django...@googlegroups.com

Mike Dewhirst

unread,
Oct 25, 2023, 9:36:53 PM10/25/23
to django...@googlegroups.com
On 25/10/2023 11:24 pm, Larry Martell wrote:
On Wed, Oct 25, 2023 at 5:35 AM Mike Dewhirst <mi...@dewhirst.com.au> wrote:
Ahmedrufai

I looked at APScheduler and like Celery it is too much of a sledgehammer for my tiny problem.

I ended up using cron to launch the command each day. It works perfectly.

My task now is to find a way to automate establishment of that crontab entry when the project is migrated to a new server.
How are new servers deployed? How many new servers will be deployed?
If it's a one off thing you are doing manually, you just have to
remember to do it.

It is a one-off but I'm assuming it will be someone else needing to do it rather than me.


 If there are many, then you should use a tool like
terraform or octopus, or something similar and have that do it.



OpenPGP_signature.asc

Mike Dewhirst

unread,
Oct 25, 2023, 9:40:30 PM10/25/23
to django...@googlegroups.com
This looks excellent, Adam. Thanks. I'll report back in due course.

Mike



-- 
Adam (ad...@csh.rit.edu)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
OpenPGP_signature.asc

Vincenzo Celano

unread,
Oct 31, 2023, 10:04:37 PM10/31/23
to django...@googlegroups.com
Try this video in YouTube:

Python Django 7 Hour Course


Ciao!

Reply all
Reply to author
Forward
0 new messages