0

I currently develop in Django. I asked a question here about background tasks and a number of people suggested a cron job. This would be the simplest solution, but my problem is, (as far as I can tell) that you can't package a cron job as part of a Django application - well that what I want to ask.

If I move server, or deploy somewhere else, is there a way to package the cron job as part of the application? I install the Django app (probably via git) and the cron job gets set automatically.

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
wobbily_col
  • 11,390
  • 12
  • 62
  • 86

1 Answers1

1

Depends on the target system your deploying to. For debian packages, the answer is yes. What you can do is put in the installation of the crontab is your postinst file. What that does is execute post package installation tasks, and you can configure that to install your crontab

For other packages (ie. Windows), I don't have expertise to answer.

However, you mentioned CRON, so I'm assuming you're installing to a Linux box :)

rurouni88
  • 1,165
  • 5
  • 10
  • OK, I am assuming a Linux box, but not a Debian install package, more likely something I can pull from git. – wobbily_col Aug 13 '14 at 09:08
  • 1
    @wobbily_col, checkout out the link that was posted as a comment to your question. http://stackoverflow.com/questions/573618/django-set-up-a-scheduled-job As an option, you could write your own post install script and make sure that gets executed once your package is installed. Apologies, but building .debs are my forte, and they conveniently support post install tasks. – rurouni88 Aug 13 '14 at 09:19
  • Yes, it looks like there are some decent solutions there. At the same time I was curious if it was possible to set an OS level cron job. – wobbily_col Aug 13 '14 at 09:22
  • Note that if you need at most hourly hits, then the `.cron.hourly` can be used an then you don't need to have a post installation script. (same with daily/monthly). – Alexis Wilke Jul 28 '21 at 23:50