def save(self): """ Updates the crontab when a task is saved. """ super(Task, self).save() update_crontab()
Description: This script is to be called directly. """ import os import sys from scheduler.models import Task, update_crontab from scheduler.views import run_task if __name__ == "__main__": # If this module is called directly, run the given task usage = 'USAGE: %s task_id' % sys.argv[0] if len(sys.argv) == 2: command = sys.argv[1] if command == "update": update_crontab() exit() # Try to parse the task id from the command if command.startswith('task_'): command = command[5:] try: task_id = int(command) except ValueError: sys.exit(usage) # Run the task matching the given task_id try: run_task(task_id) except Task.DoesNotExist: sys.exit("Task with this ID (%s) does not exist." % task_id) else: