hi guys, its a question. I need to use a scheduller to execute some functions 1 time a day etc and i wonder if Django has any built in scheduller or if not whats the scheduller you guys normally use.
Celery integrates really well with django
Django does not. If you’re currently using Celery, then Celery Beat is a good option. Beyond that, you have a lot of choices.
But you want this managed by an external process, not by your Django processes.
Isn’t it using a cannon to kill a fly? I just need to run a small function that will take a few seconds in the background. I’ve been reading and celery looks good, but it seems “too much” for what I need.
If the scheduled tasks are all you need celery for, then yes. However, if you’re already using celery for other background tasks, then you’re just taking advantage of what you already have.
However, you really haven’t provided a lot of specifics about your requirements. It’s not just that you will want to run these functions, but you may need to administer the operation of those functions - and that’s where a more sophisticated solution will help.
If you’ve got multiple functions each with different scheduling requirements, then the easiest way to administer the execution of those functions is with Celery / Beat.
On the other hand, if it’s just one function running once per day (or some trivial issue like that), then you may be better off just using
cron to run your task.
But again, Django itself is not your solution. However you choose to do this needs to be done externally to your Django processes.
The use case is very simple. i need to run one function which will run a database table and send some records to another. nothing more than 100/200 lines every day at midnight
Then my recommendation would be to create a Django custom management command and run it as a cron job.
(Side note: The size of the function(s) being executed really isn’t relevant to the discussion here. It doesn’t matter whether it’s 10 lines or 10,000 lines - it’s a Django program that needs to be run.)
My solution was create a management command.
The command works via command (python /path/to/ptoject manage.py commandName) but cron wont execute it. In cron i added
* * * * * /home/env/bin/python /home/ionv/nfcReader/manage.py recordSync. The cron is working but not execute the command. Anny ideas?
Check your log file(s) to see what messages are in there for it.
I’m guessing it’s because your current directory isn’t your BASE_DIR for your project and so it’s not finding your settings. (Just a guess)
I’d first try prepending a
cd ... && command to your command string to see if that fixes it.
(Note - you are aware that the
* * * * * specification will cause this program to run every minute?)
i will see that, yes i choose every minute to test.
Dont give any error,
Feb 1 16:37:01 raspberrypi CRON: (inov) CMD (/home/inov/env/bin/python /home/inov/nfcReader/manage.py recordSync) Feb 1 16:38:01 raspberrypi CRON: (inov) CMD (/home/inov/env/bin/python /home/inov/nfcReader/manage.py recordSync) Feb 1 16:39:01 raspberrypi CRON: (inov) CMD (/home/inov/env/bin/python /home/inov/nfcReader/manage.py recordSync)
Is that with adding the cd command?
its from the syslog, execute every minute but no error feedback
Adding cd and && worked like a charm, Thanks =)