simpleflow icon indicating copy to clipboard operation
simpleflow copied to clipboard

Support instance-based activities

Open jbbarth opened this issue 9 years ago • 8 comments

This has been discussed a little in #70 , but I open a separate issue for this. We'd like to be able to pass an object instance to Workflow.submit() directly to ease its instrumentation:

self.submit(Foo(bar))

The recent refactoring around activity tasks could help with that.

For now I have something working here: https://github.com/botify-labs/simpleflow/tree/feature/instance-based-activities but I'm not really satisfied (one more class concept, hacky generation of an Activity, "callable" still used everywhere where in fact we have an object, no automatic args/kwargs resolution, etc.). Will try to improve that later.

jbbarth avatar Dec 09 '15 18:12 jbbarth

[Speculating] Could we use metaclass thingies to defer the call to __init__ or wrap somewhat the future arguments?

ybastide avatar Dec 10 '15 08:12 ybastide

I don't know "metaclass thingies" (yet), pointer?

jbbarth avatar Dec 10 '15 08:12 jbbarth

Sorry, no pointer found... __metaclass__, __new__, __call__ or some such things, but it's hand waving...

ybastide avatar Dec 10 '15 09:12 ybastide

Oh ok, I thought there was something special in abc or equivalent to do lazy evaluation or some other black magic. I'll read the docs about metaclasses then!

jbbarth avatar Dec 10 '15 10:12 jbbarth

No magic, just metaprogramming :-)

It's easy, really. Just parse __init__'s arguments. If any is a Future, replace it with its result getter :wink:

(I discovered a really marvelous implementation that this comment box's margin is too small to contain)

ybastide avatar Dec 10 '15 11:12 ybastide

@ybastide gist it ? :)

ampelmann avatar Dec 10 '15 13:12 ampelmann

Thanks Mr Fermat ;-) Actually I may find a smart solution with __new__, didn't know you have access to that in python!

jbbarth avatar Dec 10 '15 13:12 jbbarth

Arg, last problem (but not least): examples work well with ONE instance of a given task, but they'll mix up in the registry if there are two of them. We need to refine their name to include a unique ID per object. Going down the rabbit hole :(

jbbarth avatar Dec 10 '15 13:12 jbbarth