HashtagRemoveFanoutPipeline.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 App\Hashtag;
  10. use App\StatusHashtag;
  11. use App\Services\HashtagFollowService;
  12. use App\Services\HomeTimelineService;
  13. use Illuminate\Queue\Middleware\WithoutOverlapping;
  14. use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
  15. class HashtagRemoveFanoutPipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing
  16. {
  17. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  18. protected $sid;
  19. protected $hid;
  20. public $timeout = 900;
  21. public $tries = 3;
  22. public $maxExceptions = 1;
  23. public $failOnTimeout = true;
  24. /**
  25. * The number of seconds after which the job's unique lock will be released.
  26. *
  27. * @var int
  28. */
  29. public $uniqueFor = 3600;
  30. /**
  31. * Get the unique ID for the job.
  32. */
  33. public function uniqueId(): string
  34. {
  35. return 'hfp:hashtag:fanout:remove:' . $this->hid . ':' . $this->sid;
  36. }
  37. /**
  38. * Get the middleware the job should pass through.
  39. *
  40. * @return array<int, object>
  41. */
  42. public function middleware(): array
  43. {
  44. return [(new WithoutOverlapping("hfp:hashtag:fanout:remove:{$this->hid}:{$this->sid}"))->shared()->dontRelease()];
  45. }
  46. /**
  47. * Create a new job instance.
  48. */
  49. public function __construct($sid, $hid)
  50. {
  51. $this->sid = $sid;
  52. $this->hid = $hid;
  53. }
  54. /**
  55. * Execute the job.
  56. */
  57. public function handle(): void
  58. {
  59. $sid = $this->sid;
  60. $hid = $this->hid;
  61. $ids = HashtagFollowService::getPidByHid($hid);
  62. if(!$ids || !count($ids)) {
  63. return;
  64. }
  65. foreach($ids as $id) {
  66. HomeTimelineService::rem($id, $sid);
  67. }
  68. }
  69. }