示例#1
0
def start_languagepack_download(request):
    if not request.method == 'POST':
        raise Exception(_("Must call API endpoint with POST verb."))

    data = json.loads(request.raw_post_data)  # Django has some weird post processing into request.POST, so use .body
    lang_code = lcode_to_ietf(data['lang'])

    call_command_async('retrievecontentpack', 'download', lang_code)

    return JsonResponseMessageSuccess(_("Successfully started language pack download for %(lang_name)s.") % {"lang_name": get_language_name(lang_code)})
示例#2
0
def start_languagepack_download(request):
    if not request.method == 'POST':
        raise Exception(_("Must call API endpoint with POST verb."))

    data = json.loads(request.raw_post_data)  # Django has some weird post processing into request.POST, so use .body
    lang_code = lcode_to_ietf(data['lang'])

    call_command_async('retrievecontentpack', 'download', lang_code, background=True)

    return JsonResponseMessageSuccess(_("Successfully started language pack download for %(lang_name)s.") % {"lang_name": get_language_name(lang_code)})
示例#3
0
def start_update_kalite(request):
    try:
        data = json.loads(request.body)
        mechanism = data['mechanism']
    except KeyError:
        raise KeyError(_("You did not select a valid choice for an update mechanism."))

    # Clear any preexisting logs
    if UpdateProgressLog.objects.count():
        UpdateProgressLog.objects.all().delete()

    call_command_async('update', mechanism, old_server_pid=os.getpid(), in_proc=True)

    return JsonResponseMessageSuccess(_("Launched software update process successfully."))
示例#4
0
def start_update_kalite(request):
    try:
        data = json.loads(request.body)
        mechanism = data['mechanism']
    except KeyError:
        raise KeyError(_("You did not select a valid choice for an update mechanism."))

    # Clear any preexisting logs
    if UpdateProgressLog.objects.count():
        UpdateProgressLog.objects.all().delete()

    call_command_async('update', mechanism, old_server_pid=os.getpid(), in_proc=True)

    return JsonResponseMessageSuccess(_("Launched software update process successfully."))
示例#5
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

    job.save()

    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 Job.objects.filter(disabled=False,
                              is_running=False,
                              next_run__lte=datetime.now()).count() > 0:
            # logging.debug("Ready to launch command '%s'" % command)
            call_command_async("cron")
示例#6
0
文件: utils.py 项目: Aypak/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

    job.save()

    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 Job.objects.filter(disabled=False, is_running=False, next_run__lte=datetime.now()).count() > 0:
            # logging.debug("Ready to launch command '%s'" % command)
            call_command_async("cron")