我需要heroku的一个工作人员来做一些后台任务。
在文章的第1 章中,我发现了在本文中设计的架构,并在网络平台和工作平台之间进行了通信系统的开发。
但是我不想使用 RabbitMQ,因为它在这个阶段太复杂了。
因此,作为 web dyno
和 worker dyno
之间的通信机制,我想使用以下两种方法之一:
- 数据库( 基本上是我的最佳选择:p )
- AWS ( 我可以使用它,但是数据库会更好地满足我的需要)
现在,示例提供了使用RabbitMQ的示例,使用回调使脚本处于活动状态并连续接收队列中的新邮件:
$callback = function($msg) use($app) {
$app['monolog']->debug('New task received for censoring message: '. $msg->body);
try {
//call the"censor" API and pass it the text to clean up
$result = $app['guzzle']->get('censor', ['query' => ['corpus' => $msg->body]]);
$result = json_decode($result->getBody());
if($result) {
$app['monolog']->debug('Censored message result is: '. $result->censored_text);
//store in Redis
$app['predis']->lpush('opinions', $result->censored_text);
//mark as delivered in RabbitMQ
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
} else {
$app['monolog']->warning('Failed to decode JSON, will retry later');
}
} catch(Exception $e) {
$app['monolog']->warning('Failed to call API, will retry later');
}
};
$channel->basic_qos(null, 1, null);
$channel->basic_consume('task_queue', '', false, false, false, false, $callback);
//loop over incoming messages
while(count($channel->callbacks)) {
$channel->wait();
}
我的问题是:如何在不使用RabbitMQ的情况下"仿真"命令?
换句话说,我如何使能够从数据库或者 AWS SQS读取队列,连续处理数据库或者 AWS SQS队列中出现的消息。
我应该使用 Heroku计划程序( ) 来启动调度任务?( 不适用:请参见这里的原因) 。
或者我没有考虑到另一个流程?
或者,更多的是创建基于前端应用的symfony 命令行 应用程序( ),这是一个?它会在不停止的情况下?