EventServiceProvider.php
2.71 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace App\Providers;
use AlibabaCloud\SDK\Mts\V20140618\Models\QueryJobListRequest;
use App\Helpers\UploadHelper;
use App\Models\Activity;
use App\Models\GroupHasMember;
use App\Models\ProjectDynamic;
use App\Models\UserCertify;
use App\Models\UserDynamic;
use App\Observers\ActivityObserver;
use App\Observers\GroupMemberObserver;
use App\Observers\ProjectDynamicObserver;
use App\Observers\UserCertifyObserver;
use App\Observers\UserDynamicObserver;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Redis;
use Laravel\Octane\Facades\Octane;
class EventServiceProvider extends ServiceProvider
{
/**
* The event to listener mappings for the application.
*
* @var array<class-string, array<int, class-string>>
*/
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot(): void
{
UserDynamic::observe(UserDynamicObserver::class);
UserCertify::observe(UserCertifyObserver::class);
ProjectDynamic::observe(ProjectDynamicObserver::class);
Activity::observe(ActivityObserver::class);
GroupHasMember::observe(GroupMemberObserver::class);
Octane::tick('MediaTranscodeQuery', static function () {
$jobIds = Redis::client()->sRandMember('media_transcode', 10);
if (count($jobIds) !== 0) {
$queryJobListRequest = new QueryJobListRequest(["jobIds" => implode(',', $jobIds)]);
$data = UploadHelper::getMtsClient()->queryJobList($queryJobListRequest)->body;
if ($data->nonExistJobIds) {
Redis::client()->sRem('media_transcode', $data->nonExistJobIds->string);
}
foreach ($data->jobList->job as $item) {
if ($item->state === 'TranscodeSuccess') {
Redis::client()->sRem('media_transcode', $item->jobId);
}
if ($data = json_decode($item->output->userData, true, 512, JSON_THROW_ON_ERROR)) {
$class = '\\' . ltrim('App\\Models\\' . $data['event_type'], '\\');
(new $class)->newQuery()->whereKey($data['event_id'])->update([
$data['event_attribute'] => UploadHelper::getOssDomain() . '/' . $item->output->outputFile->object
]);
}
}
}
})->seconds(10)->immediate();
}
}