fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] Serial to parallel execution


From: Hajducko, Steven
Subject: Re: [Fab-user] Serial to parallel execution
Date: Fri, 16 Dec 2011 11:36:43 -0800

Couple of comments about this now that I'm actually trying to implement
- let me know if I'm missing something:

Instead of:

@task
@parallel
def push():

I'd need:

@task
@parallel
def push(ver):
    _define_env(ver)

Since if I'm setting a bunch of environment details based on an
argument, any specific task is going to need the environment defined.  I
couldn't think of any better way to do this, since a user can basically
enter the code at any single point - I ended up with something like this
for each of my callable tasks:

@task
def package(ver):
    if not env.has_key('tarball'):
    _define_env(ver)

Also, along those lines, my command to specific tasks ( like the push
and package ) has to be something like:

fab push:1.73,role=lab

Or if I wanted, I could do something like:

@task
def package(ver,rolename):
    _package(ver,role=rolename)

Please let me know if I got something wrong or if there's a better way
to accomplish it :) This would probably all go away if I just wanted to
provide the 'deploy' task to the user, but in trying to allow the user
to execute any part of the deployment process by itself seems to be
making it a bit more complicated.

Thanks!

-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of
Jeff Forcier
Sent: Thursday, November 17, 2011 10:11 PM
To: Hajducko, Steven
Cc: address@hidden
Subject: Re: [Fab-user] Serial to parallel execution

Hi Steven,

On Wed, Nov 16, 2011 at 5:36 PM, Hajducko, Steven
<address@hidden> wrote:

> Basic premise is, want to be able to compile ( once ), then parallel
the push/install.
> Also want to use roles to be able to selectively decide which
environment to push to at runtime.

Your posted code is acceptable for what you need to do, given how
things currently work. However, another possibly cleaner alternative
would be this:

    @task
    @parallel
    def push():
        ...

    @task
    @runs_once
    def package():
        ...

    @task
    def deploy(ver, rolename):
        <set env vars>
        execute(package) # runs only once like this anyway, but
keeping @runs_once doesn't hurt
        execute(push, role=rolename)

Unless there are bugs (!) you should be able to run this like so
(note: no global host/role arguments):

    $ fab deploy:1.73,prod

while as a bonus, retaining the ability to run push() or package() as
regular standalone tasks.

The trick is omitting any global connection params, and instead
leveraging execute()'s host/role kwargs.

The only downside is that Fab auto-interprets certain task args
("host", "roles" etc -- see execution docs) so you have to use some
name other than "role" or Fab will still end up running 'deploy' with
a host list.

FWIW, if this pattern becomes more prevalent I might add an option to
disable auto-interpretation so you can use more natural kwarg names.

> Also, is there a better way to test directory existence that I'm
missing?

Try fabric.contrib.files.exists :) (It's in the 'contrib' API docs.)


Best,
Jeff

-- 
Jeff Forcier
Unix sysadmin; Python/Ruby engineer
http://bitprophet.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]