Queue.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 stopping(mixed $callback)
  12. * @method static bool connected(string|null $name = null)
  13. * @method static \Illuminate\Contracts\Queue\Queue connection(string|null $name = null)
  14. * @method static void extend(string $driver, \Closure $resolver)
  15. * @method static void addConnector(string $driver, \Closure $resolver)
  16. * @method static string getDefaultDriver()
  17. * @method static void setDefaultDriver(string $name)
  18. * @method static string getName(string|null $connection = null)
  19. * @method static \Illuminate\Contracts\Foundation\Application getApplication()
  20. * @method static \Illuminate\Queue\QueueManager setApplication(\Illuminate\Contracts\Foundation\Application $app)
  21. * @method static int size(string|null $queue = null)
  22. * @method static mixed push(string|object $job, mixed $data = '', string|null $queue = null)
  23. * @method static mixed pushOn(string $queue, string|object $job, mixed $data = '')
  24. * @method static mixed pushRaw(string $payload, string|null $queue = null, array $options = [])
  25. * @method static mixed later(\DateTimeInterface|\DateInterval|int $delay, string|object $job, mixed $data = '', string|null $queue = null)
  26. * @method static mixed laterOn(string $queue, \DateTimeInterface|\DateInterval|int $delay, string|object $job, mixed $data = '')
  27. * @method static mixed bulk(array $jobs, mixed $data = '', string|null $queue = null)
  28. * @method static \Illuminate\Contracts\Queue\Job|null pop(string|null $queue = null)
  29. * @method static string getConnectionName()
  30. * @method static \Illuminate\Contracts\Queue\Queue setConnectionName(string $name)
  31. * @method static mixed getJobTries(mixed $job)
  32. * @method static mixed getJobBackoff(mixed $job)
  33. * @method static mixed getJobExpiration(mixed $job)
  34. * @method static void createPayloadUsing(callable|null $callback)
  35. * @method static \Illuminate\Container\Container getContainer()
  36. * @method static void setContainer(\Illuminate\Container\Container $container)
  37. * @method static \Illuminate\Support\Testing\Fakes\QueueFake except(array|string $jobsToBeQueued)
  38. * @method static void assertPushed(string|\Closure $job, callable|int|null $callback = null)
  39. * @method static void assertPushedOn(string $queue, string|\Closure $job, callable|null $callback = null)
  40. * @method static void assertPushedWithChain(string $job, array $expectedChain = [], callable|null $callback = null)
  41. * @method static void assertPushedWithoutChain(string $job, callable|null $callback = null)
  42. * @method static void assertClosurePushed(callable|int|null $callback = null)
  43. * @method static void assertClosureNotPushed(callable|null $callback = null)
  44. * @method static void assertNotPushed(string|\Closure $job, callable|null $callback = null)
  45. * @method static void assertCount(int $expectedCount)
  46. * @method static void assertNothingPushed()
  47. * @method static \Illuminate\Support\Collection pushed(string $job, callable|null $callback = null)
  48. * @method static bool hasPushed(string $job)
  49. * @method static bool shouldFakeJob(object $job)
  50. * @method static array pushedJobs()
  51. * @method static \Illuminate\Support\Testing\Fakes\QueueFake serializeAndRestore(bool $serializeAndRestore = true)
  52. *
  53. * @see \Illuminate\Queue\QueueManager
  54. * @see \Illuminate\Queue\Queue
  55. * @see \Illuminate\Support\Testing\Fakes\QueueFake
  56. */
  57. class Queue extends Facade
  58. {
  59. /**
  60. * Register a callback to be executed to pick jobs.
  61. *
  62. * @param string $workerName
  63. * @param callable $callback
  64. * @return void
  65. */
  66. public static function popUsing($workerName, $callback)
  67. {
  68. return Worker::popUsing($workerName, $callback);
  69. }
  70. /**
  71. * Replace the bound instance with a fake.
  72. *
  73. * @param array|string $jobsToFake
  74. * @return \Illuminate\Support\Testing\Fakes\QueueFake
  75. */
  76. public static function fake($jobsToFake = [])
  77. {
  78. $actualQueueManager = static::isFake()
  79. ? static::getFacadeRoot()->queue
  80. : static::getFacadeRoot();
  81. return tap(new QueueFake(static::getFacadeApplication(), $jobsToFake, $actualQueueManager), function ($fake) {
  82. static::swap($fake);
  83. });
  84. }
  85. /**
  86. * Get the registered name of the component.
  87. *
  88. * @return string
  89. */
  90. protected static function getFacadeAccessor()
  91. {
  92. return 'queue';
  93. }
  94. }