Queue.php 6.6 KB

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