コード例 #1
0
ファイル: action.py プロジェクト: ncorona/notredam
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()
コード例 #2
0
ファイル: action.py プロジェクト: mlclemente/notredam
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()
コード例 #3
0
ファイル: action.py プロジェクト: ncorona/notredam
 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
コード例 #4
0
ファイル: action.py プロジェクト: mlclemente/notredam
 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