初始化仓库
This commit is contained in:
34
common/jobs/MessageSendJob.php
Normal file
34
common/jobs/MessageSendJob.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user