Maintain local ⭤ remote in sync with automatic AT Protocol parity for Laravel (alpha & unstable)
1<?php
2
3namespace SocialDept\AtpParity\Jobs;
4
5use Illuminate\Bus\Queueable;
6use Illuminate\Contracts\Queue\ShouldQueue;
7use Illuminate\Foundation\Bus\Dispatchable;
8use Illuminate\Queue\InteractsWithQueue;
9use Illuminate\Queue\SerializesModels;
10use SocialDept\AtpParity\Import\ImportService;
11
12class ImportUserJob implements ShouldQueue
13{
14 use Dispatchable;
15 use InteractsWithQueue;
16 use Queueable;
17 use SerializesModels;
18
19 /**
20 * The number of times the job may be attempted.
21 */
22 public int $tries = 3;
23
24 /**
25 * The number of seconds to wait before retrying.
26 */
27 public int $backoff = 60;
28
29 public function __construct(
30 public string $did,
31 public ?string $collection = null,
32 ) {
33 $this->onQueue(config('parity.import.queue', 'default'));
34 }
35
36 public function handle(ImportService $service): void
37 {
38 $collections = $this->collection ? [$this->collection] : null;
39 $service->importUser($this->did, $collections);
40 }
41
42 /**
43 * Get the tags that should be assigned to the job.
44 *
45 * @return array<string>
46 */
47 public function tags(): array
48 {
49 $tags = ['parity-import', "did:{$this->did}"];
50
51 if ($this->collection) {
52 $tags[] = "collection:{$this->collection}";
53 }
54
55 return $tags;
56 }
57}