simpleflow
simpleflow copied to clipboard
Support instance-based activities
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.
[Speculating] Could we use metaclass thingies to defer the call to __init__
or wrap somewhat the future arguments?
I don't know "metaclass thingies" (yet), pointer?
Sorry, no pointer found... __metaclass__
, __new__
, __call__
or some such things, but it's hand waving...
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!
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 gist it ? :)
Thanks Mr Fermat ;-) Actually I may find a smart solution with __new__
, didn't know you have access to that in python!
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 :(