IncrementPostCount.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Jobs\ProfilePipeline;
  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\Profile;
  12. use App\Status;
  13. use App\Services\AccountService;
  14. class IncrementPostCount implements ShouldQueue, ShouldBeUniqueUntilProcessing
  15. {
  16. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  17. public $id;
  18. public $timeout = 900;
  19. public $tries = 3;
  20. public $maxExceptions = 1;
  21. public $failOnTimeout = true;
  22. /**
  23. * The number of seconds after which the job's unique lock will be released.
  24. *
  25. * @var int
  26. */
  27. public $uniqueFor = 3600;
  28. /**
  29. * Get the unique ID for the job.
  30. */
  31. public function uniqueId(): string
  32. {
  33. return 'propipe:ipc:' . $this->id;
  34. }
  35. /**
  36. * Get the middleware the job should pass through.
  37. *
  38. * @return array<int, object>
  39. */
  40. public function middleware(): array
  41. {
  42. return [(new WithoutOverlapping("propipe:ipc:{$this->id}"))->shared()->dontRelease()];
  43. }
  44. /**
  45. * Create a new job instance.
  46. *
  47. * @return void
  48. */
  49. public function __construct($id)
  50. {
  51. $this->id = $id;
  52. }
  53. /**
  54. * Execute the job.
  55. *
  56. * @return void
  57. */
  58. public function handle()
  59. {
  60. $id = $this->id;
  61. $profile = Profile::find($id);
  62. if(!$profile) {
  63. return 1;
  64. }
  65. $profile->status_count = $profile->status_count + 1;
  66. $profile->last_status_at = now();
  67. $profile->save();
  68. AccountService::del($id);
  69. AccountService::get($id);
  70. return 1;
  71. }
  72. }