Beanstalkd - 访问同一队列的多个worker

时间:2013-09-28 01:45:28

标签: beanstalkd

我想在部署过程中使用Beanstalkd。这个想法类似于IGN使用的想法(https://github.com/ign/brood)。在任何给定的时间我可能想触发两个客户端下载最新的代码并重启Apache。是否可以让多个工作者(每个客户端一个)处理同一个队列?作为一种解决方法,我可以为每个客户端创建一个队列。

1 个答案:

答案 0 :(得分:0)

每个客户端的特定队列,用于该客户端的命令。让他们全部听取自己的队列,并根据需要向尽可能多的客户端发送简单的“RESTART”消息。

我有一个启动作业的bash脚本,并使其保持运行执行实际的重启。你的脚本只需要

  1. 删除'RESTART'消息(否则下次会收到相同的消息)
  2. exit(90);脚本
  3. 返回值由Bash脚本获取,并执行操作。

    #!/bin/bash
    
    # runBeanstalkd-worker.sh
    
    # a shell script that keeps looping until an exit code is given
    # if it does an exit(0), restart after a second - or if it's a declared error
    # if we've restarted in a planned fashion, we don't bother with any pause
    # and for one particular code, exit the script entirely.
    # The numbers 97, 98, 99 must match what is returned from the PHP script
    
    nice php -q -f ./cli-beanstalk-worker.php -- $@
    ERR=$?
    
    ## Possibilities
    # 90    - restart apache
    # 97    - planned pause/restart
    # 98    - planned restart
    # 99    - planned stop, exit.
    # 0     - unplanned restart (as returned by "exit;")
    #        - Anything else is also unplanned paused/restart
    
    # 90    - restart apache
    if [ $ERR -eq 90 ]
    then
       service apache restart
       sleep 5;
       exec $0 $@;
    fi
    
    if [ $ERR -eq 97 ]
    then
       # a planned pause, then restart
       echo "97: PLANNED_PAUSE - wait 1";
       sleep 1;
       exec $0 $@;
    fi
    
    ####   other actions, like planned-restart, or shutdown
    
    # unplanned exit, pause, and restart
    echo "unplanned restart: err:" $ERR;
    echo "sleeping for 1 sec"
    sleep 1
    
    exec $0 $@