Queue.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace Illuminate\Support\Facades;
  3. use Illuminate\Queue\Worker;
  4. use Illuminate\Support\Testing\Fakes\QueueFake;
  5. /**
  6. * @method static void before(mixed $callback)
  7. * @method static void after(mixed $callback)
  8. * @method static void exceptionOccurred(mixed $callback)
  9. * @method static void looping(mixed $callback)
  10. * @method static void failing(mixed $callback)
  11. * @method static void starting(mixed $callback)
  12. * @method static void stopping(mixed $callback)
  13. * @method static bool connected(string|null $name = null)
  14. * @method static \Illuminate\Contracts\Queue\Queue connection(string|null $name = null)
  15. * @method static void pause(string $connection, string $queue)
  16. * @method static void pauseFor(string $connection, string $queue, \DateTimeInterface|\DateInterval|int $ttl)
  17. * @method static void resume(string $connection, string $queue)
  18. * @method static bool isPaused(string $connection, string $queue)
  19. * @method static void withoutInterruptionPolling()
  20. * @method static void extend(string $driver, \Closure $resolver)
  21. * @method static void addConnector(string $driver, \Closure $resolver)
  22. * @method static string getDefaultDriver()
  23. * @method static void setDefaultDriver(string $name)
  24. * @method static string getName(string|null $connection = null)
  25. * @method static \Illuminate\Contracts\Foundation\Application getApplication()
  26. * @method static \Illuminate\Queue\QueueManager setApplication(\Illuminate\Contracts\Foundation\Application $app)
  27. * @method static int size(string|null $queue = null)
  28. * @method static mixed push(string|object $job, mixed $data = '', string|null $queue = null)
  29. * @method static mixed pushOn(string $queue, string|object $job, mixed $data = '')
  30. * @method static mixed pushRaw(string $payload, string|null $queue = null, array $options = [])
  31. * @method static mixed later(\DateTimeInterface|\DateInterval|int $delay, string|object $job, mixed $data = '', string|null $queue = null)
  32. * @method static mixed laterOn(string $queue, \DateTimeInterface|\DateInterval|int $delay, string|object $job, mixed $data = '')
  33. * @method static mixed bulk(array $jobs, mixed $data = '', string|null $queue = null)
  34. * @method static \Illuminate\Contracts\Queue\Job|null pop(string|null $queue = null)
  35. * @method static string getConnectionName()
  36. * @method static \Illuminate\Contracts\Queue\Queue setConnectionName(string $name)
  37. * @method static int pendingSize(string|null $queue = null)
  38. * @method static int delayedSize(string|null $queue = null)
  39. * @method static int reservedSize(string|null $queue = null)
  40. * @method static int|null creationTimeOfOldestPendingJob(string|null $queue = null)
  41. * @method static mixed getJobTries(mixed $job)
  42. * @method static mixed getJobBackoff(mixed $job)
  43. * @method static mixed getJobExpiration(mixed $job)
  44. * @method static void createPayloadUsing(callable|null $callback)
  45. * @method static array getConfig()
  46. * @method static \Illuminate\Queue\Queue setConfig(array $config)
  47. * @method static \Illuminate\Container\Container getContainer()
  48. * @method static void setContainer(\Illuminate\Container\Container $container)
  49. * @method static \Illuminate\Support\Testing\Fakes\QueueFake except(array|string $jobsToBeQueued)
  50. * @method static void assertPushed(string|\Closure $job, callable|int|null $callback = null)
  51. * @method static void assertPushedTimes(string $job, int $times = 1)
  52. * @method static void assertPushedOn(string $queue, string|\Closure $job, callable|null $callback = null)
  53. * @method static void assertPushedWithChain(string $job, array $expectedChain = [], callable|null $callback = null)
  54. * @method static void assertPushedWithoutChain(string $job, callable|null $callback = null)
  55. * @method static void assertClosurePushed(callable|int|null $callback = null)
  56. * @method static void assertClosureNotPushed(callable|null $callback = null)
  57. * @method static void assertNotPushed(string|\Closure $job, callable|null $callback = null)
  58. * @method static void assertCount(int $expectedCount)
  59. * @method static void assertNothingPushed()
  60. * @method static \Illuminate\Support\Collection pushed(string $job, callable|null $callback = null)
  61. * @method static \Illuminate\Support\Collection pushedRaw(null|\Closure $callback = null)
  62. * @method static \Illuminate\Support\Collection listenersPushed(string $listenerClass, \Closure|null $callback = null)
  63. * @method static bool hasPushed(string $job)
  64. * @method static bool shouldFakeJob(object $job)
  65. * @method static array pushedJobs()
  66. * @method static array rawPushes()
  67. * @method static \Illuminate\Support\Testing\Fakes\QueueFake serializeAndRestore(bool $serializeAndRestore = true)
  68. * @method static void releaseUniqueJobLocks()
  69. *
  70. * @see \Illuminate\Queue\QueueManager
  71. * @see \Illuminate\Queue\Queue
  72. * @see \Illuminate\Support\Testing\Fakes\QueueFake
  73. */
  74. class Queue extends Facade
  75. {
  76. /**
  77. * Register a callback to be executed to pick jobs.
  78. *
  79. * @param string $workerName
  80. * @param callable $callback
  81. * @return void
  82. */
  83. public static function popUsing($workerName, $callback)
  84. {
  85. Worker::popUsing($workerName, $callback);
  86. }
  87. /**
  88. * Replace the bound instance with a fake.
  89. *
  90. * @param array|string $jobsToFake
  91. * @return \Illuminate\Support\Testing\Fakes\QueueFake
  92. */
  93. public static function fake($jobsToFake = [])
  94. {
  95. $actualQueueManager = static::isFake()
  96. ? tap(static::getFacadeRoot(), fn ($fake) => $fake->releaseUniqueJobLocks())->queue
  97. : static::getFacadeRoot();
  98. return tap(new QueueFake(static::getFacadeApplication(), $jobsToFake, $actualQueueManager), function ($fake) {
  99. static::swap($fake);
  100. });
  101. }
  102. /**
  103. * Replace the bound instance with a fake that fakes all jobs except the given jobs.
  104. *
  105. * @param string[]|string $jobsToAllow
  106. * @return \Illuminate\Support\Testing\Fakes\QueueFake
  107. */
  108. public static function fakeExcept($jobsToAllow)
  109. {
  110. return static::fake()->except($jobsToAllow);
  111. }
  112. /**
  113. * Replace the bound instance with a fake during the given callable's execution.
  114. *
  115. * @param callable $callable
  116. * @param array $jobsToFake
  117. * @return mixed
  118. */
  119. public static function fakeFor(callable $callable, array $jobsToFake = [])
  120. {
  121. $originalQueueManager = static::getFacadeRoot();
  122. static::fake($jobsToFake);
  123. try {
  124. return $callable();
  125. } finally {
  126. static::swap($originalQueueManager);
  127. }
  128. }
  129. /**
  130. * Replace the bound instance with a fake during the given callable's execution.
  131. *
  132. * @param callable $callable
  133. * @param array $jobsToAllow
  134. * @return mixed
  135. */
  136. public static function fakeExceptFor(callable $callable, array $jobsToAllow = [])
  137. {
  138. $originalQueueManager = static::getFacadeRoot();
  139. static::fakeExcept($jobsToAllow);
  140. try {
  141. return $callable();
  142. } finally {
  143. static::swap($originalQueueManager);
  144. }
  145. }
  146. /**
  147. * Get the registered name of the component.
  148. *
  149. * @return string
  150. */
  151. protected static function getFacadeAccessor()
  152. {
  153. return 'queue';
  154. }
  155. }