Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
ProcessShortcutCategoryAsyncJob | |
0.00% |
0 / 11 |
|
0.00% |
0 / 6 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
handle | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
backoff | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
created | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
updateUserInfo | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
parseFields | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace App\Jobs; |
4 | |
5 | use App\Http\Models\ShortcutCategory; |
6 | use Illuminate\Bus\Queueable; |
7 | use Illuminate\Contracts\Queue\ShouldQueue; |
8 | use Illuminate\Foundation\Bus\Dispatchable; |
9 | use Illuminate\Queue\InteractsWithQueue; |
10 | use Illuminate\Queue\SerializesModels; |
11 | use App\Http\Models\UserInfo; |
12 | use MongoDB\BSON\UTCDateTime; |
13 | |
14 | class ProcessShortcutCategoryAsyncJob implements ShouldQueue |
15 | { |
16 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
17 | |
18 | public $tries = 5; |
19 | |
20 | public function __construct( |
21 | public ShortcutCategory $shortcutCategory, |
22 | public string $action |
23 | ) {} |
24 | |
25 | public function handle(): void |
26 | { |
27 | if ($this->action === 'created') { |
28 | $this->created($this->shortcutCategory); |
29 | } |
30 | } |
31 | |
32 | public function backoff() |
33 | { |
34 | return [10, 30, 60, 110, 300]; |
35 | } |
36 | |
37 | private function created(ShortcutCategory $shortcutCategory): void |
38 | { |
39 | $parsedFields = $this->parseFields($shortcutCategory); |
40 | |
41 | $this->updateUserInfo($parsedFields, $shortcutCategory); |
42 | } |
43 | |
44 | private function updateUserInfo(array $data, ShortcutCategory $shortcutCategory) |
45 | { |
46 | UserInfo::where('user_id', $shortcutCategory->user_id)->update($data); |
47 | } |
48 | |
49 | private function parseFields(ShortcutCategory $shortcutCategory): array |
50 | { |
51 | return [ |
52 | 'number_of_categories_created_last_date' => new UTCDateTime($shortcutCategory->created_at->timestamp * 1000), |
53 | 'number_of_categories_created_count' => ShortcutCategory::where('user_id', $shortcutCategory->user_id)->count(), |
54 | ]; |
55 | } |
56 | } |