threefoldtecharchive / 0-robot

Distributed live cycle management system
Apache License 2.0
0 stars 0 forks source link

Seemless service interface #22

Open rkhamis opened 6 years ago

rkhamis commented 6 years ago

Issue migrated from [https://api.github.com/repos/zero-os/0-robot/issues/186](), opened by @FastGeert

A way to make template code more easible to read, is to expose the actions as methods on the service proxy object.

Synchronous action invocations

# Seemless way
result = myservice.install(reinstall=True)
# Current way
result = myservice.schedule_action("install", args=dict(reinstall=True)).wait(die=True).result

Asynchronous actions invocations

# Seemless way
task = myservice.install_async(reinstall=True)
result = task.get_result() # Blocks and might throw exception (eco)
# Current way
task = myservice.schedule_action("install", args=dict(reinstall=True))
task.wait()
if task.state == 'error':
    raise task.eco
else:
    result = task.result
rkhamis commented 6 years ago

commented by @zaibon I'll play a bit with this idea and see to integrate in next version.