【发布时间】:2018-02-05 16:50:29
【问题描述】:
我有一个由 Phalcon 提供支持的 RESTful API,需要后台处理一些任务。
在 MailController 中,我有一个从 Imap 获取邮件的方法。由于我需要在这里放一些慢的东西,我想通过工作来处理它。
我的路由调用了一个mailAction,作业被启动,作业应该在这个控制器中执行。
Services.php
$di->setShared("queue", function(){
$queue = new Beanstalk([
"host" => "127.0.0.1",
"port" => "11300"
]);
return $queue;
});
(di 中的 Beanstalk 服务声明)
MailController.php
public function fetchMailboxAction(){
$queue = $this->di->getShared("queue");
$idQueue = $queue->put([
"readMailbox" => [
"email" => $this->email,
"customer_id" => $this->customer_id
]
],
[
"priority" => 250,
"delay" => 10,
"ttr" => 3600
]);
/* other stuff, return blah blah */
}
public function readMailbox($params){
// readMailboxStuff that should be executed through the job
}
我的问题:如何指定 Beanstalkd 必须在哪个控制器中执行我的功能的作业?文档非常规避,我不确定我是否做得很好!
谢谢
【问题讨论】:
标签: php phalcon beanstalkd