[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Fab-user] Executing a block of code once for task that has multiple
From: |
Jeff Forcier |
Subject: |
Re: [Fab-user] Executing a block of code once for task that has multiple hosts |
Date: |
Wed, 5 Oct 2011 14:09:31 -0700 |
On Wed, Oct 5, 2011 at 1:43 PM, Ahsan Rabbani <address@hidden> wrote:
> Is it possible to have certain code executed only once even if a task has
> multiple hosts defined (without having to invoke multiple tasks from the
> command line)?
In Fab 1.2 and below, one way to do this is to flip it around and use
@runs_once:
@runs_once
def compile():
# This runs one time only, regardless of how many times
compile() is called
@hosts("host1", "host2", ...)
def compile_and_rsync():
compile() # Innards of compile() will only actually execute once
# but everything in here runs once per host, so rsync or whatnot.
Invoke as:
$ fab compile_and_rsync
Fabric 1.3 will have execute(), which should feel less backwards:
@hosts("host1", "host2", ...)
def rsync_files(projects):
# rsync here
def compile_and_rsync():
# Anything in here runs just once because we're not using @hosts.
# (Unless you use -H, of course...)
compile() # or whatever
execute(rsync_files) # This honors rsync_files' @hosts and
loops over the hosts
1.3 is due out in the next week or two (hopefully sooner -- wrapping
up execute() work now -- but we're waiting on some dependency issues
that involve a third party.)
Best,
Jeff
--
Jeff Forcier
Unix sysadmin; Python/Ruby engineer
http://bitprophet.org