BrokerPushLevelRecordItemRollBackJob.php
1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace App\Jobs;
use App\Enums\BrokerPushLevelRecordStatusEnum;
use App\Helpers\IMHelper;
use App\Models\BrokerPushLevelRecordItem;
use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Redis;
use Throwable;
class BrokerPushLevelRecordItemRollBackJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, Batchable;
public BrokerPushLevelRecordItem $recordItem;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(BrokerPushLevelRecordItem $recordItem)
{
$this->recordItem = $recordItem;
$this->queue = 'im_rollback';
}
/**
* Execute the job.
*
* @return void
* @throws \Exception
*/
public function handle(): void
{
Redis::throttle('im-rollback')->allow(200)->every(1)->then(function () {
$this->recordItem->update(['status' => BrokerPushLevelRecordStatusEnum::PROCESSING]);
$result = IMHelper::rollbackChatMessage(IMHelper::SYSTEM_USER, $this->recordItem->getAttribute('user_id'), $this->recordItem->getAttribute('message_id'))->json('ActionStatus');
$this->recordItem->update(['status' => $result === 'OK' ? BrokerPushLevelRecordStatusEnum::ROLLBACK : BrokerPushLevelRecordStatusEnum::SUCCESS]);
}, function () {
$this->release(1);
});
}
public function failed(Throwable $exception): void
{
$this->recordItem->update(['status' => BrokerPushLevelRecordStatusEnum::SUCCESS]);
}
}