我们有一个在多个主机上并行运行的 Python fabric 命令,如下所示:
$ fab --hosts=prod1.server,prod2.server,prod3.server --parallel copy_cache
这会将缓存复制到并行列出的生产服务器。整个过程中会出现各种日志记录,以表明我们的进度,因为 XXgig 缓存目录可能需要几个小时。由于复制是同时进行的,因此在命令行上运行时的输出会实时交错,如下所示:
[prod1.server] Executing task 'nginx_cache_copy'
[prod2.server] Executing task 'nginx_cache_copy'
[prod3.server] Executing task 'nginx_cache_copy'
2014-09-16 10:02:29.688243
[prod1.server] INFO: rsyncing cache dir
[prod1.server] run: rsync -a -q cache.server:"repo/cache/some.site.com" \
"repo/cache/."
2014-09-16 10:02:29.716345
[prod2.server] INFO: rsyncing cache dir
[prod2.server] run: rsync -a -q cache.server:"repo/cache/some.site.com" \
"repo/cache/."
2014-09-16 10:02:29.853275
[prod3.server] INFO: rsyncing cache dir
[prod3.server] run: rsync -a -q cache.server:"repo/cache/some.site.com" \
"repo/cache/."
2014-09-16 10:02:29.984154
[prod1.server] INFO: Reloading nginx config
[prod1.server] run: sbin/nginx -s reload -c "repo/nginx.conf"
2014-09-16 10:02:30.025155
[prod2.server] INFO: Reloading nginx config
[prod2.server] run: sbin/nginx -s reload -c "repo/nginx.conf"
2014-09-16 10:02:30.100169
[prod1.server] SUCCESS: CACHE COPY COMPLETE
2014-09-16 10:02:30.181938
[prod2.server] SUCCESS: CACHE COPY COMPLETE
2014-09-16 10:02:30.331402
[prod3.server] INFO: Reloading nginx config
[prod3.server] run: sbin/nginx -s reload -c "repo/nginx.conf"
2014-09-16 10:02:30.559271
[prod3.server] SUCCESS: CACHE COPY COMPLETE
Done.
但是,当通过 Jenkins 运行任务时,控制台输出直到所有任务完成才会显示,因为 Jenkins 在所有线程完成后线程连接后对输出进行分组。因此,一旦所有命令完成,输出将如下所示:
[prod1.server] Executing task 'nginx_cache_copy'
2014-09-16 10:02:29.688243
[prod1.server] INFO: rsyncing cache dir
[prod1.server] run: rsync -a -q cache.server:"repo/cache/some.site.com" \
"repo/cache/."
2014-09-16 10:02:29.984154
[prod1.server] INFO: Reloading nginx config
[prod1.server] run: sbin/nginx -s reload -c "repo/nginx.conf"
2014-09-16 10:02:30.100169
[prod1.server] SUCCESS: CACHE COPY COMPLETE
[prod2.server] Executing task 'nginx_cache_copy'
2014-09-16 10:02:29.716345
[prod2.server] INFO: rsyncing cache dir
[prod2.server] run: rsync -a -q cache.server:"repo/cache/some.site.com" \
"repo/cache/."
2014-09-16 10:02:30.025155
[prod2.server] INFO: Reloading nginx config
[prod2.server] run: sbin/nginx -s reload -c "repo/nginx.conf"
2014-09-16 10:02:30.181938
[prod2.server] SUCCESS: CACHE COPY COMPLETE
[prod3.server] Executing task 'nginx_cache_copy'
2014-09-16 10:02:29.853275
[prod3.server] INFO: rsyncing cache dir
[prod3.server] run: rsync -a -q cache.server:"repo/cache/some.site.com" \
"repo/cache/."
2014-09-16 10:02:30.331402
[prod3.server] INFO: Reloading nginx config
[prod3.server] run: sbin/nginx -s reload -c "repo/nginx.conf"
2014-09-16 10:02:30.559271
[prod3.server] SUCCESS: CACHE COPY COMPLETE
Done.
虽然这更具可读性,但并不理想,因为我们希望通过实时读取控制台输出来跟踪进程的状态。请注意,当运行此 fabric 命令时没有--parallel
控制台输出的选项确实实时发生,但这显然是不可行的,因为串行过程需要更长的时间才能运行。
我在 Jenkins 中找不到可以禁用此线程分组的设置。有人有什么想法吗?