3 回答

TA貢獻(xiàn)1911條經(jīng)驗(yàn) 獲得超7個(gè)贊
通常,對(duì)于此類(lèi)異步任務(wù)處理,Celery是首選。 這詳細(xì)說(shuō)明了芹菜和織物的結(jié)合使用。
from fabric.api import hosts, env, execute,run
from celery import task
env.skip_bad_hosts = True
env.warn_only = True
@task()
def my_celery_task(testhost):
host_string = "%s@%s" % (testhost.SSH_user_name, testhost.IP)
@hosts(host_string)
def my_fab_task():
env.password = testhost.SSH_password
run("ls")
try:
result = execute(my_fab_task)
if isinstance(result.get(host_string, None), BaseException):
raise result.get(host_string)
except Exception as e:
print "my_celery_task -- %s" % e.message
添加回答
舉報(bào)