コード例 #1
0
ファイル: __init__.py プロジェクト: msidd/provision
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")
コード例 #2
0
ファイル: jobs.py プロジェクト: mjptak/ka-lite
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)
コード例 #3
0
ファイル: jobs.py プロジェクト: timwhit123/ka-lite
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")
コード例 #4
0
ファイル: __init__.py プロジェクト: AbhiUnni/ka-lite
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")
コード例 #5
0
def start_languagepack_download(request):
    if request.POST:
        data = json.loads(request.raw_post_data) # Django has some weird post processing into request.POST, so use raw_post_data
        call_command_async(
            'languagepackdownload',
            manage_py_dir=settings.PROJECT_PATH,
            language=data['lang']) # TODO: migrate to force_job once it can accept command_args
        return JsonResponse({'success': True})
コード例 #6
0
def start_languagepack_download(request):
    if request.POST:
        data = json.loads(
            request.raw_post_data
        )  # Django has some weird post processing into request.POST, so use raw_post_data
        call_command_async(
            'languagepackdownload',
            manage_py_dir=settings.PROJECT_PATH,
            language=data['lang']
        )  # TODO: migrate to force_job once it can accept command_args
        return JsonResponse({'success': True})
コード例 #7
0
ファイル: api_views.py プロジェクト: AbhiUnni/ka-lite
def start_update_kalite(request):
    data = json.loads(request.raw_post_data)

    if request.META.get("CONTENT_TYPE", "") == "application/json" and "url" in data:
        # Got a download url
        call_command_async("update", url=data["url"], in_proc=False, manage_py_dir=settings.PROJECT_PATH)

    elif request.META.get("CONTENT_TYPE", "") == "application/zip":
        # Streamed a file; save and call
        fp, tempfile = tempfile.mkstmp()
        with fp:
            write(request.content)
        call_command_async("update", zip_file=tempfile, in_proc=False, manage_py_dir=settings.PROJECT_PATH)

    return JsonResponse({})
コード例 #8
0
def start_update_kalite(request):
    data = json.loads(request.raw_post_data)

    if request.META.get("CONTENT_TYPE",
                        "") == "application/json" and "url" in data:
        # Got a download url
        call_command_async("update",
                           url=data["url"],
                           manage_py_dir=settings.PROJECT_PATH)

    elif request.META.get("CONTENT_TYPE", "") == "application/zip":
        # Streamed a file; save and call
        fp, tempfile = tempfile.mkstmp()
        with fp:
            write(request.content)
        call_command_async("update",
                           zip_file=tempfile,
                           manage_py_dir=settings.PROJECT_PATH)

    return JsonResponse({})