0

I need to run a specific manage.py commands on an EC2 instance every X minutes. For example: python manage.py some_command.

I have looked up django-chronograph. Following the instructions, I've added chronograph to my settings.py but on runserver it keeps telling me No module named chronograph.

Is there something I'm missing to get this running? And after running how do I get manage.py commands to run using chronograph?

Edit: It's installed in the EC2 instance's virtualenv.

Newtt
  • 6,050
  • 13
  • 68
  • 106
  • 1
    you can run cron jobs.. here are the instructions for EC2: http://docs.aws.amazon.com/opsworks/latest/userguide/workingcookbook-extend-cron.html – Sasa Oct 21 '14 at 13:19
  • 1
    Did you install django-chronograph in your virtualenv? If so, are you using the python executable from within your virtualenv's bin directory? – schillingt Oct 21 '14 at 13:21

3 Answers3

1

I would suggest you to configure cron to run your command at specific times/intervals.

HAL
  • 2,011
  • 17
  • 10
  • Is it possible to run without using crontab? – Newtt Oct 21 '14 at 13:20
  • Well, if you decide to use cron you will have to configure which jobs to run in a crontab file. – HAL Oct 21 '14 at 13:27
  • Thing is crontab is blocked for me. So I need to run it without using crontab. – Newtt Oct 21 '14 at 13:54
  • Are you sure that crontab is blocked on your EC2 instance? Have you tried editing the crontab by using "crontab -e" ? If you do not have cron support, you will not be able to use django-cronograph either AFAIK. – HAL Oct 21 '14 at 14:44
  • I was able to get Chronograph working. However, i get a Timezone error in chronograph. Any idea how to solve this? – Newtt Oct 21 '14 at 15:50
  • Without knowing more details about your problem, it is hard to help out. I would suggest you to post another question regarding the new problem. – HAL Oct 21 '14 at 16:25
0

First, install it by running pip install django-chronograph.

Pratik Mandrekar
  • 9,362
  • 4
  • 45
  • 65
0

I would say handle this through cross, but if you don't want to use cross then: Make sure you installed the module in the virtualenv (With easy_install, pip, or any other way that Amazon EC2 allows). After that you might want to look up the threading module documentation:

Python 2 threading module documentation

Python 3 threading module documentation

The purpose of using threading will be to have the following structure:

A "control" thread, which will use the chronograph module and do the time measurements, and putting the new work to do in an "input queue" on each scheduled time, for the worker threads (which will be active already) to process, or just trigger each worker thread (make it active) at the time you want to trigger each execution.
In the first case you'll be taking advantage of parallel threads to do a big chunk of work and minimize io wait times, but since the work is in a queue, the workers will process one at a time. Meaning if you schedule two things too close together and the previous element is still being processed, the new item will have to wait (Depending on your programming logic and amount of worker threads some workers might start processing the new item, but is a bit more complex logic).
In the second case your control thread will actually trigger the start of a new thread (or group of threads) each time you want to trigger a scheduled action. If there's big data to process you might need to spawn a new queue for each task to process and create a group of worker threads for it for each task, but if the data is not that big then you can just get away with having the worker process just one data package and be done once execution is done and you get a result. Either way this method will allow you to schedule tasks without limitation on how close they can be, since new independent worker threads will be created for them every time.

Finally, you might want to create an "output queue" and output thread, to store and process (or output, or anything else you want to do with it...) the results of each worker threads.

The control thread will be basically trying to imitate cron in its logic, triggering actions at certain times depending on how it was configured.
There's also a multiprocessing module in python which will work with processes instead and take advantage of true multiprocessing hardware, but I don't think you'll really need it in this case, unless you see performance issues caused by cpu performance.

If you need any clarification, help, examples, just let me know.

jcabrera
  • 136
  • 5