Esempio n. 1
0
 def setUp(self):
     """Setup cache as well as request and result."""
     self.storage = Storage.create()
     self.cache = Cache.create(storage=self.storage)
     self.request = Runnable(func=_runnable,
                             args=('this is an arg', ),
                             cacheable=True)
     self.result = 'something'
Esempio n. 2
0
 def decode_runnable(raw):
     return (raw.id,
             Runnable(
                 self._from_id(raw.func.id_),
                 tuple(
                     self._from_value(arg)
                     for arg in self._native.unpack(
                         raw.args_ptr, raw.args_len)),
                 bool(raw.cacheable)))
Esempio n. 3
0
    def test_state_roundtrips(self):
        states = [
            Return('a'),
            Throw(PickleableException()),
            Waiting([TaskNode(None, None, None)]),
            Runnable(_runnable, ('an arg', )),
            Noop('nada {}', ('op', ))
        ]
        with closing(self.storage) as storage:
            for state in states:
                key = storage.put_state(state)
                actual = storage.get_state(key)

                self.assertEquals(state, actual)
                self.assertEquals(key, storage.put_state(actual))
Esempio n. 4
0
 def setUp(self):
     self.storage = Storage.create()
     self.result = 'something'
     self.request = Runnable(func=_runnable, args=('this is an arg', ))
Esempio n. 5
0
  def step(self, step_context):
    waiting_nodes = []
    # Get the binary.
    binary_state = step_context.select_for(Select(self.snapshotted_process.binary_type),
                                           subject=self.subject,
                                           variants=self.variants)
    if type(binary_state) is Throw:
      return binary_state
    elif type(binary_state) is Waiting:
      waiting_nodes.extend(binary_state.dependencies)
    elif type(binary_state) is Noop:
      return Noop("Couldn't find binary: {}".format(binary_state))
    elif type(binary_state) is not Return:
      State.raise_unrecognized(binary_state)

    # Create the request from the request callback after resolving its input clauses.
    input_values = []
    for input_selector in self.snapshotted_process.input_selectors:
      sn_state = step_context.select_for(input_selector, self.subject, self.variants)
      if type(sn_state) is Waiting:
        waiting_nodes.extend(sn_state.dependencies)
      elif type(sn_state) is Return:
        input_values.append(sn_state.value)
      elif type(sn_state) is Noop:
        if input_selector.optional:
          input_values.append(None)
        else:
          return Noop('Was missing value for (at least) input {}'.format(input_selector))
      elif type(sn_state) is Throw:
        return sn_state
      else:
        State.raise_unrecognized(sn_state)

    if waiting_nodes:
      return Waiting(waiting_nodes)

    # Now that we've returned on waiting, we can assume that relevant inputs have values.
    try:
      process_request = self.snapshotted_process.input_conversion(*input_values)
    except Exception as e:
      return Throw(e)

    # Request snapshots for the snapshot_subjects from the process request.
    snapshot_subjects_value = []
    if process_request.snapshot_subjects:
      snapshot_subjects_state = step_context.select_for(SelectDependencies(Snapshot,
                                                                           SnapshottedProcessRequest,
                                                                           'snapshot_subjects',
                                                                           field_types=(Files,)),
                                                        process_request,
                                                        self.variants)
      if type(snapshot_subjects_state) is not Return:
        return snapshot_subjects_state
      snapshot_subjects_value = snapshot_subjects_state.value

    # Ready to run.
    execution = _Process(step_context.snapshot_archive_root,
                         process_request,
                         binary_state.value,
                         snapshot_subjects_value,
                         self.snapshotted_process.output_conversion)
    return Runnable(_execute, (execution,))