def job_done(f): if f.exception(): self.log.error("job %s occurs error. exception info %s" % (job.id, f.exception_info())) else: self.log.debug("job %s finish, result=%s" % (job.id, f.result())) if job.filter_key and job.filter_value: rpc_client_call("finish_job", job.id, job.filter_key, job.filter_value)
def submit_job(self, func, job_key, args=None, kwargs=None, trigger=None, job_id=None, replace_exist=False, filter_key='', filter_value='', **trigger_args): """ submit job to master through rpc :type func: str or callable obj or unicode :type job_key: str or unicode :type args: tuple or list :type kwargs: dict :type trigger: str or unicode :type job_id: str or unicode :type replace_exist: bool :type trigger_args: dict """ job_key = '%s:%s' % (self.name, job_key) # use worker's timezone if trigger don't provide specific `timezone` configuration trigger_args['timezone'] = self.timezone job_in_dict = { 'id': job_id, 'func': func, 'args': args, 'trigger': create_trigger(trigger, trigger_args) if trigger else None, 'kwargs': kwargs, 'filter_key': '%s_%s' % (self.name, filter_key), 'filter_value': filter_value, } job = Job(**job_in_dict) rpc_client_call('submit_job', Binary(job.serialize()), job_key, job.id, replace_exist)
def update_job(self, job_id, job_key, next_run_time, serialized_job): """ send update job request to master through rpc :type job_id: str :type job_key: str :type next_run_time: datetime.datetime :type serialized_job: str """ job_key = '%s:%s' % (self.name, job_key) rpc_client_call('update_job', job_id, job_key, next_run_time, Binary(serialized_job))
def remove_job(self, job_id): """ send remove job request to master through rpc :type job_id: str """ rpc_client_call('remove_job', job_id)