Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if it makes sense to add callbacks functionality #3

Closed
dbarrosop opened this issue Nov 25, 2017 · 2 comments
Closed

check if it makes sense to add callbacks functionality #3

dbarrosop opened this issue Nov 25, 2017 · 2 comments

Comments

@dbarrosop
Copy link
Contributor

on_error and on_success for the run method that is.

@dbarrosop
Copy link
Contributor Author

dbarrosop commented Nov 25, 2017

Not sure how useful the on_success is:

Assuming:

def something_else(result):
    if result.changed:
        print("I feel different")
    else:
        print("I feel the same")

You could do either:

def my_task(task):
    r = do_something(...)
    do_something_else(r)

brigade.run(my_task)

Or

def my_task(task):
    r = do_something(...)
    return r

brigade.run(my_task, on_success=something_else)

And both would actually do the same. I actually feel on_success would be more rigid and hard to read. With a direct call I have full control of the arguments so I can do:

def reload_service(result, service):
   if result.changed:
          reload(service)

def deploy_apache(task):
    r = do_something(...)
    reload_service(r, service="apache")

def deploy_mysql(task):
    r = do_something(...)
    reload_service(r, service="mysql")


brigade.run(deploy_apache)
brigade.run(deploy_mysql)

I think on_error is more interesting though as it would let you handle tasks that failed in an uncontrolled manner. For example, you could log an error and print something on the screen or ask the user to cancel the execution or move forward ignoring the error.

@dbarrosop
Copy link
Contributor Author

I don't think we need this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant