Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| ProcessSubCategoryLv1AsyncJob | |
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 Illuminate\Bus\Queueable; |
| 6 | use Illuminate\Contracts\Queue\ShouldQueue; |
| 7 | use Illuminate\Foundation\Bus\Dispatchable; |
| 8 | use Illuminate\Queue\InteractsWithQueue; |
| 9 | use Illuminate\Queue\SerializesModels; |
| 10 | use App\Http\Models\UserInfo; |
| 11 | use App\Http\Models\ShortcutSubCategoryLv1; |
| 12 | use MongoDB\BSON\UTCDateTime; |
| 13 | |
| 14 | class ProcessSubCategoryLv1AsyncJob implements ShouldQueue |
| 15 | { |
| 16 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
| 17 | |
| 18 | public $tries = 5; |
| 19 | |
| 20 | public function __construct( |
| 21 | public ShortcutSubCategoryLv1 $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(ShortcutSubCategoryLv1 $shortcutCategory): void |
| 38 | { |
| 39 | $parsedFields = $this->parseFields($shortcutCategory); |
| 40 | |
| 41 | $this->updateUserInfo($parsedFields, $shortcutCategory); |
| 42 | } |
| 43 | |
| 44 | private function updateUserInfo(array $data, ShortcutSubCategoryLv1 $shortcutCategory) |
| 45 | { |
| 46 | UserInfo::where('user_id', $shortcutCategory->user_id)->update($data); |
| 47 | } |
| 48 | |
| 49 | private function parseFields(ShortcutSubCategoryLv1 $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' => ShortcutSubCategoryLv1::where('user_id', $shortcutCategory->user_id)->count(), |
| 54 | ]; |
| 55 | } |
| 56 | } |