46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs\Api;
|
|
|
|
use App\Bean\Queue\Api\QueueAddPostBean;
|
|
use App\Exceptions\ModelException;
|
|
use App\Models\Api\Post\PostPushBoxModel;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class AddPostQueue implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
//处理用户的推文推送
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
* @throws ModelException
|
|
*/
|
|
public function handle(array $params): void
|
|
{
|
|
$bean = new QueueAddPostBean($params);
|
|
$oPostPushBoxModel = new PostPushBoxModel();
|
|
$oPostPushBoxModel->addPostQueueConsumer($bean);
|
|
}
|
|
|
|
public static function putToQueue(QueueAddPostBean $bean,$delaySec = null): \Illuminate\Foundation\Bus\PendingDispatch
|
|
{
|
|
$queue = self::dispatch($bean->toArrayNotNull())->onQueue(QueueAddPostBean::QUEUE_NAME);
|
|
if(!empty($delaySec)){
|
|
$queue->delay(now()->addSeconds($delaySec));
|
|
}
|
|
return $queue;
|
|
}
|
|
}
|