Tzook Bar Noy
Tzook Bar Noy

Reputation: 11677

python fabric run function once for all servers

we have a deploy script that has 5 servers, we want to run the script and notify us only once even though it runs for 5 servers.

The example code:

env.hosts = ['web1', 'web2', 'web3', 'web4', 'web5']

def notify():
    sendNotify()

@task
def deploy():
    sendNotify()
    deploy stuff
    deploy stuff
    deploy stuff
    deploy stuff

I want that notify will be called only once, but because there are 5 servers it is called 5 times.

Upvotes: 1

Views: 337

Answers (1)

ronnix
ronnix

Reputation: 1564

Maybe you can use the @runs_once decorator on notify.

See: http://fabric.readthedocs.org/en/1.3.4/api/core/decorators.html#fabric.decorators.runs_once

Upvotes: 1

Related Questions