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")
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.")) call_command_async('update', mechanism, old_server_pid=os.getpid(), in_proc=True) return JsonResponseMessageSuccess(_("Launched software update process successfully."))
def start_update_kalite(request): try: data = json.loads(request.raw_post_data) mechanism = data['mechanism'] except KeyError: raise KeyError(_("You did not select a valid choice for an update mechanism.")) call_command_async('update', mechanism, old_server_pid=os.getpid(), in_proc=True) return JsonResponseMessageSuccess(_("Launched software update process successfully."))
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."))
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({})
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."))