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, **kwargs):
    """
    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 = job.name or name or command

    #
    if stop:
        job.is_running = False
    else:
        job.next_run = datetime.now()
        job.args = " ".join(["%s=%s" % (k, v) for k, v in kwargs.iteritems()])

    #
    job.save()

    # Set as variable so that we could pass as param later, if we want to!
    launch_job = not stop and not job.is_running
    if launch_job:  # don't run the same job twice
        # 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_ready_count() > 0:
            # logging.debug("Ready to launch command '%s'" % command)
            call_command_async("cron")
Beispiel #3
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 #4
0
def force_job(command, name="", frequency="YEARLY", stop=False, **kwargs):
    """
    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 = job.name or name or command

    #
    if stop:
        job.is_running = False
    else:
        job.next_run = datetime.now()
        job.args = " ".join(["%s=%s" % (k, v) for k, v in kwargs.iteritems()])

    #
    job.save()

    # Set as variable so that we could pass as param later, if we want to!
    launch_job = not stop and not job.is_running
    if launch_job:  # don't run the same job twice
        # 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_ready_count() > 0:
            # logging.debug("Ready to launch command '%s'" % command)
            call_command_async("cron")
Beispiel #5
0
def force_job(command, name="", frequency="YEARLY", stop=False):
    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()
Beispiel #6
0
def force_job(command, name="", frequency="YEARLY", stop=False):
    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()