FeedWarmCachePipeline.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\Services\HomeTimelineService;
  10. use Illuminate\Queue\Middleware\WithoutOverlapping;
  11. use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
  12. class FeedWarmCachePipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing
  13. {
  14. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  15. protected $pid;
  16. public $timeout = 900;
  17. public $tries = 3;
  18. public $maxExceptions = 1;
  19. public $failOnTimeout = true;
  20. /**
  21. * The number of seconds after which the job's unique lock will be released.
  22. *
  23. * @var int
  24. */
  25. public $uniqueFor = 3600;
  26. /**
  27. * Get the unique ID for the job.
  28. */
  29. public function uniqueId(): string
  30. {
  31. return 'hfp:warm-cache:pid:' . $this->pid;
  32. }
  33. /**
  34. * Get the middleware the job should pass through.
  35. *
  36. * @return array<int, object>
  37. */
  38. public function middleware(): array
  39. {
  40. return [(new WithoutOverlapping("hfp:warm-cache:pid:{$this->pid}"))->shared()->dontRelease()];
  41. }
  42. /**
  43. * Create a new job instance.
  44. */
  45. public function __construct($pid)
  46. {
  47. $this->pid = $pid;
  48. }
  49. /**
  50. * Execute the job.
  51. */
  52. public function handle(): void
  53. {
  54. $pid = $this->pid;
  55. HomeTimelineService::warmCache($pid, true, 400, true);
  56. }
  57. }