FeedRemovePipeline.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Jobs\HomeFeedPipeline;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Contracts\Queue\ShouldBeUnique;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Foundation\Bus\Dispatchable;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Queue\SerializesModels;
  9. use Illuminate\Queue\Middleware\WithoutOverlapping;
  10. use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
  11. use App\Services\FollowerService;
  12. use App\Services\StatusService;
  13. use App\Services\HomeTimelineService;
  14. class FeedRemovePipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing
  15. {
  16. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  17. protected $sid;
  18. protected $pid;
  19. public $timeout = 900;
  20. public $tries = 3;
  21. public $maxExceptions = 1;
  22. public $failOnTimeout = true;
  23. /**
  24. * The number of seconds after which the job's unique lock will be released.
  25. *
  26. * @var int
  27. */
  28. public $uniqueFor = 3600;
  29. /**
  30. * Get the unique ID for the job.
  31. */
  32. public function uniqueId(): string
  33. {
  34. return 'hts:feed:remove:sid:' . $this->sid;
  35. }
  36. /**
  37. * Get the middleware the job should pass through.
  38. *
  39. * @return array<int, object>
  40. */
  41. public function middleware(): array
  42. {
  43. return [(new WithoutOverlapping("hts:feed:remove:sid:{$this->sid}"))->shared()->dontRelease()];
  44. }
  45. /**
  46. * Create a new job instance.
  47. */
  48. public function __construct($sid, $pid)
  49. {
  50. $this->sid = $sid;
  51. $this->pid = $pid;
  52. }
  53. /**
  54. * Execute the job.
  55. */
  56. public function handle(): void
  57. {
  58. $ids = FollowerService::localFollowerIds($this->pid);
  59. HomeTimelineService::rem($this->pid, $this->sid);
  60. foreach($ids as $id) {
  61. HomeTimelineService::rem($id, $this->sid);
  62. }
  63. }
  64. }