【问题标题】:Email sending as background process using CakeResque使用 CakeResque 作为后台进程发送电子邮件
【发布时间】:2013-10-07 09:50:58
【问题描述】:

MailShell.php

<?php

App::uses('AppShell', 'Console/Command');
App::uses('CakeEmail', 'Network/Email');

class MailShell extends AppShell
{

    public function sendMail() {
        $Email = new CakeEmail();
        $Email->from(array('admin@localhost' => 'My Site'));
        $Email->to($this->args[1]);
        $Email->subject($this->args[3]);
        $Email->send($this->args[2]);
    }
}

TestController.php

<?php
App::uses('AppController', 'Controller');

class TestController extends AppController {

    public function index(){
        CakeResque::enqueue('default','CakeResque.Mail', array('sendMail','test@gmail.com','Test Email','Hi this it test email.'));
    }
}

当我打开网址时

http://localhost/test/index

作业在默认队列中正确排队请参阅

当我开始工作时,统计数据如下所示

对于每个作业,它会将已处理作业增加 1 个失败作业增加 2 个,并且不发送电子邮件

什么是真正的问题?电子邮件发送程序有问题吗? CakeResque 有问题吗?

任何帮助表示赞赏

谢谢

【问题讨论】:

    标签: php email backgroundworker background-process cakephp-2.4


    【解决方案1】:

    从 TestController 排队作业时使用

    CakeResque::enqueue('default',
                        'CakeResque.MailShell',   //difference is here
                         array('sendMail',
                               'test@gmail.com',
                               'Test Email',
                               'Hi this it test email.'));
    

    而不是

    CakeResque::enqueue('default',
                        'CakeResque.Mail',                                   
                         array('sendMail',
                              'test@gmail.com',
                              'Test Email',
                              'Hi this it test email.'));
    

    【讨论】:

    • TestController 不必找到 MailShell,因为它从不使用它。问题是您在排队队列时引用 Job 类的方式,在 CakeResque::enqueue 中引用队列时使用 CakeResque.MailShell 而不是 CakeResque.Mail
    • @Kamisama,感谢您的回复,代码现在正在运行,但仍然不明白为什么它增加了失败的工作,尽管工作成功进行并且您的教程很好。
    • 你应该在 github 上开一张票,包含重现问题所需的一切
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-11
    • 2013-10-01
    • 2022-07-28
    • 2014-01-01
    • 2015-08-07
    • 2017-10-23
    • 2011-09-13
    相关资源
    最近更新 更多