我有一个要求,我必须不断从AWS-SQS(简单队列服务)获取消息并更新模型的相关记录。该消息包含需要在获取相关用户后立即显示为通知的数据。使用Action Cable成功管理了此问题。我创建了一个rake任务,它从队列中获取消息并执行所需的处理。该任务应该在无限循环中运行。我有2个问题吗?
namespace :sqs_consumer do
desc 'Get data from the AWS-SQS and process it.'
task start: :environment do
# initialize the sqs client
loop do
#read the queue for messages and process them in batches(if any)
end
end
end
1)为上述要求创建rake任务是否正确?无限运行的rake任务是正确的方法吗?如果没有,那么正确的方法是什么。我不能定期运行任务,因为我需要实时数据。
2)我想监控任务。我正在使用monit。不幸的是,Monit conf同样似乎不起作用。我做错了什么或错过了什么?
check process aws_sqs_consumer with pidfile /var/www/myproject/shared/pids/sqs_consumer.pid
start program = "/bin/sh -c 'cd /var/www/myproject/current; nohup bundle exec rake sqs_consumer:start RAILS_ENV=staging -i 0 -P /var/www/myproject/shared/pids/sqs_consumer.pid >> log/sqs_consumer.log 2>&1 &'" as uid ubuntu and gid ubuntu
stop program = "/bin/sh -c 'kill $(cat /var/www/myproject/shared/pids/sqs_consumer.pid)'" as uid ubuntu and gid ubuntu
答案 0 :(得分:0)
这个monit配置对我有用
check process aws_sqs_consumer with pidfile /var/www/myproject/shared/tmp/pids/sqs_consumer.pid
start program = "/bin/sh -c 'cd /var/www/myproject/current && BACKGROUND=y PIDFILE=/var/www/myproject/shared/tmp/pids/sqs_consumer.pid LOG_LEVEL=info bundle exec rake sqs_consumer:start RAILS_ENV=staging'"
stop program = "/bin/sh -c 'kill $(cat /var/www/myproject/shared/tmp/pids/sqs_consumer.pid)'" as uid ubuntu and gid ubuntu with timeout 90 seconds