def create_harvest_job(self, request, queryset): job_batch_id = Manually.instance().job_batch_id result = None failed_objects = [] for publish in queryset: result = JobStatemachine.create_job(publish.id, Manually.instance(), job_batch_id) if not result[0]: failed_objects.append( ("{0}:{1}".format(publish.workspace.name, publish.name), result[1])) if failed_objects: messages.warning( request, mark_safe( "Create job failed for some selected publishs:<ul>{0}</ul>" .format("".join([ "<li>{0} : {1}</li>".format(o[0], o[1]) for o in failed_objects ])))) else: messages.success( request, "Create job successfully for all selected publishs")
def create_harvest_job(self,request,queryset): job_batch_id = Manually.instance().job_batch_id result = None failed_objects = [] for publish in queryset: result = JobStatemachine.create_job(publish.id,Manually.instance(),job_batch_id) if not result[0]: failed_objects.append(("{0}:{1}".format(publish.workspace.name,publish.name),result[1])) if failed_objects: messages.warning(request, mark_safe("Create job failed for some selected publishs:<ul>{0}</ul>".format("".join(["<li>{0} : {1}</li>".format(o[0],o[1]) for o in failed_objects])))) else: messages.success(request, "Create job successfully for all selected publishs")
def _create_job(publish, job_interval=Manually.instance(), job_batch_id=None): """ manually create a job return (true,'OK'), if create a job, otherwise return (False,message) """ if not publish.publish_status.publish_enabled: #publish is disabled, ignore return (False, "Disabled") if publish.waiting > 0: #already have one waiting harvest job, create another is meanless. return (False, "Already have a waiting job") if not job_batch_id: job_batch_id = Manually.instance().job_batch_id job = None with transaction.atomic(): if publish.waiting > 0: #already have one waiting harvest job, create another is meanless. return publish.waiting = models.F("waiting") + 1 job = Job(batch_id=job_batch_id, publish=publish, state=Waiting.instance().name, previous_state=None, message=None, created=timezone.now(), launched=None, finished=None, job_type=job_interval.name) publish.save(update_fields=['waiting']) job.save() #add log log = JobLog( job_id=job.id, state="Create", outcome="Create", message="Created by custodian" if job_interval == Manually.instance() else "Created by other application", next_state=job.state, start_time=timezone.now(), end_time=timezone.now()) log.save() return (True, job.id)
def _create_job(publish,job_interval=Manually.instance(),job_batch_id=None): """ manually create a job return (true,'OK'), if create a job, otherwise return (False,message) """ if not publish.publish_status.publish_enabled: #publish is disabled, ignore return (False,"Disabled") if publish.waiting > 0: #already have one waiting harvest job, create another is meanless. return (False,"Already have a waiting job") if not job_batch_id: job_batch_id = Manually.instance().job_batch_id job = None with transaction.atomic(): if publish.waiting > 0: #already have one waiting harvest job, create another is meanless. return; publish.waiting = models.F("waiting") + 1 job = Job( batch_id = job_batch_id, publish = publish, state = Waiting.instance().name, previous_state = None, message = None, created = timezone.now(), launched = None, finished = None, job_type = job_interval.name ) publish.save(update_fields=['waiting']) job.save() #add log log = JobLog( job_id = job.id, state = "Create", outcome = "Create", message = "Created by custodian" if job_interval == Manually.instance() else "Created by other application", next_state = job.state, start_time = timezone.now(), end_time = timezone.now()) log.save() return (True,job.id)
def handle(self, *args, **options): # Parse the days argument as an integer. if options['interval_choice']: if options['publish_id'] or options['publish_name'] : raise Exception("Three options cannot be used together.") else: interval = JobInterval.get_interval(options['interval_choice']) JobStatemachine.create_jobs(interval) elif options['publish_id']: if options['publish_name']: raise Exception("Three options cannot be used together.") else: JobStatemachine.create_job(options['publish_id'],Manually.instance()) elif options['publish_name']: JobStatemachine.create_job_by_name(options['publish_name'],Manually.instance()) else: raise Exception("No option is specified") return 0
def create_job(publish_id,job_interval=Manually.instance(),job_batch_id=None): """ manually create a job by id """ p = None try: p = Publish.objects.get(pk=publish_id) except: return (False,"Not exist") return JobStatemachine._create_job(p,job_interval,job_batch_id)
def create_job(publish_id, job_interval=Manually.instance(), job_batch_id=None): """ manually create a job by id """ p = None try: p = Publish.objects.get(pk=publish_id) except: return (False, "Not exist") return JobStatemachine._create_job(p, job_interval, job_batch_id)
def handle(self, *args, **options): # Parse the days argument as an integer. if options['interval_choice']: if options['publish_id'] or options['publish_name']: raise Exception("Three options cannot be used together.") else: interval = JobInterval.get_interval(options['interval_choice']) JobStatemachine.create_jobs(interval) elif options['publish_id']: if options['publish_name']: raise Exception("Three options cannot be used together.") else: JobStatemachine.create_job(options['publish_id'], Manually.instance()) elif options['publish_name']: JobStatemachine.create_job_by_name(options['publish_name'], Manually.instance()) else: raise Exception("No option is specified") return 0
def create_job_by_name(publish_name,job_interval=Manually.instance(),job_batch_id=None): """ manually create a job by name """ components = publish_name.split('.', 1) p = None try: if len(components) == 2: w = Workspace.objects.get(name=components[0]) p = Publish.objects.get(name=components[1], workspace=w) else: p = Publish.objects.get(name=publish_name) except: return (False,"Not exist") return JobStatemachine._create_job(p,job_interval,job_batch_id)
def create_job_by_name(publish_name, job_interval=Manually.instance(), job_batch_id=None): """ manually create a job by name """ components = publish_name.split('.', 1) p = None try: if len(components) == 2: w = Workspace.objects.get(name=components[0]) p = Publish.objects.get(name=components[1], workspace=w) else: p = Publish.objects.get(name=publish_name) except: return (False, "Not exist") return JobStatemachine._create_job(p, job_interval, job_batch_id)