Beispiel #1
0
def force_job(command, name="", frequency="YEARLY", stop=False, launch_cron=True):
    """
    Mark a job as to run immediately (or to stop).
    By default, call cron directly, to resolve.
    """
    jobs = Job.objects.filter(command=command)
    if jobs.count() > 0:
        job = jobs[0]
    else:
        job = Job(command=command)
        job.frequency = frequency
        job.name = name or command

    if stop:
        job.is_running = False
    else:
        job.next_run = datetime.now()
    job.save()

    if launch_cron:
        # Just start cron directly, so that the process starts immediately.
        # Note that if you're calling force_job frequently, then 
        # you probably want to avoid doing this on every call.
        if get_count() and not job_status(command):
            logging.debug("Ready to launch command '%s'" % command)
            call_command_async("cron", manage_py_dir=settings.PROJECT_PATH)
Beispiel #2
0
def force_job(command,
              name="",
              frequency="YEARLY",
              stop=False,
              launch_cron=True):
    """
    Mark a job as to run immediately (or to stop).
    By default, call cron directly, to resolve.
    """
    jobs = Job.objects.filter(command=command)
    if jobs.count() > 0:
        job = jobs[0]
    else:
        job = Job(command=command)
        job.frequency = frequency
        job.name = name or command

    if stop:
        job.is_running = False
    else:
        job.next_run = datetime.now()
    job.save()

    if launch_cron:
        # Just start cron directly, so that the process starts immediately.
        # Note that if you're calling force_job frequently, then
        # you probably want to avoid doing this on every call.
        if get_count() and not job_status(command):
            logging.debug("Ready to launch command '%s'" % command)
            call_command_async("cron")
Beispiel #3
0
def cron():
    # only bother spinning up the full cron management command if there's something waiting to be run
    if get_count():
        # Use sys to get the same executable running as is running this process.
        # Make sure to call the manage.py from this project.
        subprocess.call([sys.executable, os.path.join(settings.PROJECT_PATH, "manage.py"), "cron"])

    # This is the pause between executions.  If the above hangs for a long time,
    #   we won't check again until it has returned / completed.
    threading.Timer(settings.CRONSERVER_FREQUENCY, cron).start()
Beispiel #4
0
def cron():
    # only bother spinning up the full cron management command if there's something waiting to be run
    if get_count():
        subprocess.call(["python", "manage.py", "cron"])
    threading.Timer(5, cron).start()
Beispiel #5
0
def cron():
    # only bother spinning up the full cron management command if there's something waiting to be run
    if get_count():
        subprocess.call(["python", "manage.py", "cron"])
    threading.Timer(5, cron).start()