class Action: def __init__(self, job_id=None): if job_id: self.job = memcache.get(job_id) or Job.objects.get(job_id=job_id) self.decoded_params = loads(self.job.params) else: self.job = Job() self.decoded_params = [['dummy'] ] # first function is always discarded def push(self, function_name, *function_params): self.decoded_params.append([function_name, function_params]) return self def set_component(self, component): self.job.component = component return self def execute(self, data): "This changes the state of the job and it is not undoable" if not self.job.component: raise ('Error: executing action with no component') self.decoded_params.remove(self.decoded_params[0]) if self.decoded_params: self.job.params = dumps(self.decoded_params) self.job.save() fname, fparams = self.decoded_params[0] func = getattr(processors, fname) log.debug('Action.executing: %s' % fname) return func(self, data, *fparams) else: raise ActionError('Attempt to execute an empty action') def retire(self): self.job.delete()
class Action: def __init__(self, job_id=None): if job_id: self.job = memcache.get(job_id) or Job.objects.get(job_id=job_id) self.decoded_params = loads(self.job.params) else: self.job = Job( ) self.decoded_params = [ ['dummy'] ] # first function is always discarded def push(self, function_name, *function_params): self.decoded_params.append([function_name, function_params]) return self def set_component(self, component): self.job.component = component return self def execute(self, data): "This changes the state of the job and it is not undoable" if not self.job.component: raise('Error: executing action with no component') self.decoded_params.remove(self.decoded_params[0]) if self.decoded_params: self.job.params = dumps(self.decoded_params) self.job.save() fname, fparams = self.decoded_params[0] func = getattr(processors, fname) log.debug('Action.executing: %s' % fname) return func(self, data, *fparams) else: raise ActionError('Attempt to execute an empty action') def retire(self): self.job.delete()
def __init__(self, job_id=None): if job_id: self.job = memcache.get(job_id) or Job.objects.get(job_id=job_id) self.decoded_params = loads(self.job.params) else: self.job = Job() self.decoded_params = [['dummy'] ] # first function is always discarded
def __init__(self, job_id=None): if job_id: self.job = memcache.get(job_id) or Job.objects.get(job_id=job_id) self.decoded_params = loads(self.job.params) else: self.job = Job( ) self.decoded_params = [ ['dummy'] ] # first function is always discarded