35 lines
775 B
PHP
35 lines
775 B
PHP
<?php
|
|
namespace common\jobs;
|
|
|
|
|
|
use common\services\ImService;
|
|
use yii\queue\Queue;
|
|
use yii\queue\RetryableJobInterface;
|
|
|
|
//避免消息发送影响正常逻辑,所有的消息发送单独挪动出来
|
|
class MessageSendJob extends BaseJob implements RetryableJobInterface
|
|
{
|
|
public $ims_id;
|
|
public $to_id;
|
|
public $to_role;
|
|
public $content;
|
|
|
|
/**
|
|
* @param Queue $queue which pushed and is handling the job
|
|
*/
|
|
public function execute($queue)
|
|
{
|
|
ImService::getInstance()->sendToUid($this->ims_id,$this->to_id,$this->to_role,$this->content);
|
|
}
|
|
|
|
public function getTtr()
|
|
{
|
|
return 60;
|
|
}
|
|
|
|
public function canRetry($attempt, $error)
|
|
{
|
|
return ($attempt < 5) && ($error instanceof \Exception);
|
|
}
|
|
}
|