在apscheduler中执行fabric的定时任务时:
正常的写法是这样的
scheduler.add_job(updataPicture.gettime, 'cron', day_of_week='0-6', hour=18, minute=15)
可是在时间到达的时候执行结果是这样的:
No hosts found. Please specify (single) host string for connection:
结果会让我从新输入主机名api
通过查询在Stack Overflow上找了答案:ide
In order to get hosts to work in a script outside of the fab command-line tool and fabfile.py, you'll have to use execute(): from fabric.tasks import execute def mytask(): run('uname -a') results = execute(mytask)
这样的话主机就能够工做在脚本之外了,我在原有fabric文件中执行code
def getlatestpics(): execute(updatapic)
而后定时任务这样:ip
scheduler.add_job(updataPicture.getlatestpics, 'cron', day_of_week='0-6', hour=18, minute=15)
这样就能够很是完美的执行了ci