[openstack-dev] [oslo] Asyncio and oslo.messaging

Joshua Harlow harlowja at yahoo-inc.com
Tue Jul 8 19:31:16 UTC 2014


I think clints response was likely better than what I can write here, but
I'll add-on a few things,


>How do you write such code using taskflow?
>
>  @asyncio.coroutine
>  def foo(self):
>      result = yield from some_async_op(...)
>      return do_stuff(result)

The idea (at a very high level) is that users don't write this;

What users do write is a workflow, maybe the following (pseudocode):

# Define the pieces of your workflow.

TaskA():
  def execute():
      # Do whatever some_async_op did here.

  def revert():
      # If execute had any side-effects undo them here.
  
TaskFoo():
   ...

# Compose them together

flow = linear_flow.Flow("my-stuff").add(TaskA("my-task-a"),
TaskFoo("my-foo"))

# Submit the workflow to an engine, let the engine do the work to execute
it (and transfer any state between tasks as needed).

The idea here is that when things like this are declaratively specified
the only thing that matters is that the engine respects that declaration;
not whether it uses asyncio, eventlet, pigeons, threads, remote
workers[1]. It also adds some things that are not (imho) possible with
co-routines (in part since they are at such a low level) like stopping the
engine after 'my-task-a' runs and shutting off the software, upgrading it,
restarting it and then picking back up at 'my-foo'.

Hope that helps make it a little more understandable :)

-Josh

[1] http://docs.openstack.org/developer/taskflow/workers.html




More information about the OpenStack-dev mailing list