NotificationEpochUpdatePipeline.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Jobs\InternalPipeline;
  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\Notification;
  12. use Cache;
  13. use App\Services\NotificationService;
  14. class NotificationEpochUpdatePipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing
  15. {
  16. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  17. public $timeout = 1500;
  18. public $tries = 3;
  19. public $maxExceptions = 1;
  20. public $failOnTimeout = true;
  21. /**
  22. * The number of seconds after which the job's unique lock will be released.
  23. *
  24. * @var int
  25. */
  26. public $uniqueFor = 3600;
  27. /**
  28. * Get the unique ID for the job.
  29. */
  30. public function uniqueId(): string
  31. {
  32. return 'ip:notification-epoch-update';
  33. }
  34. /**
  35. * Get the middleware the job should pass through.
  36. *
  37. * @return array<int, object>
  38. */
  39. public function middleware(): array
  40. {
  41. return [(new WithoutOverlapping('ip:notification-epoch-update'))->shared()->dontRelease()];
  42. }
  43. /**
  44. * Create a new job instance.
  45. */
  46. public function __construct()
  47. {
  48. //
  49. }
  50. /**
  51. * Execute the job.
  52. */
  53. public function handle(): void
  54. {
  55. $rec = Notification::where('created_at', '>', now()->subMonths(6))->first();
  56. $id = 1;
  57. if($rec) {
  58. $id = $rec->id;
  59. }
  60. Cache::put(NotificationService::EPOCH_CACHE_KEY . '6', $id, 1209600);
  61. }
  62. }