Skip to content

Instantly share code, notes, and snippets.

@arseniy-panfilov
Created May 31, 2017 15:12
Show Gist options
  • Save arseniy-panfilov/ebbdddcd7a13a7802679216246be4f9b to your computer and use it in GitHub Desktop.
Save arseniy-panfilov/ebbdddcd7a13a7802679216246be4f9b to your computer and use it in GitHub Desktop.
exception in parallel task - fabfile boilerplate
from fabric.api import env, execute, lcd, task, settings
from fabric.decorators import runs_once, parallel
env.roledefs = {
'foo': ['bar1', 'bar2', 'bar3']
}
class FabricAbortException(Exception):
pass
@task
@parallel
def parallel_task():
if env.host_string != 'bar1':
raise Exception("error in %s" % env.host_string)
print("success for %s" % env.host_string)
@runs_once
@task
def main_task():
thrown_error = None
errors_fired = 0
with settings(abort_exception=FabricAbortException):
try:
with lcd("/tmp"):
execute(parallel_task)
except Exception as err:
thrown_error = err
errors_fired += 1
if thrown_error is not None:
print("errors fired: %s" % errors_fired)
raise thrown_error
print("all done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment