PheanstalkInterface.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. namespace Pheanstalk\Contract;
  3. use Pheanstalk\Job;
  4. interface PheanstalkInterface
  5. {
  6. const DEFAULT_PORT = 11300;
  7. const DEFAULT_DELAY = 0; // no delay
  8. const DEFAULT_PRIORITY = 1024; // most urgent: 0, least urgent: 4294967295
  9. const DEFAULT_TTR = 60; // 1 minute
  10. const DEFAULT_TUBE = 'default';
  11. // ----------------------------------------
  12. /**
  13. * Puts a job into a 'buried' state, revived only by 'kick' command.
  14. */
  15. public function bury(JobIdInterface $job, int $priority = self::DEFAULT_PRIORITY): void;
  16. /**
  17. * Permanently deletes a job.
  18. */
  19. public function delete(JobIdInterface $job): void;
  20. /**
  21. * Remove the specified tube from the watchlist.
  22. *
  23. * Does not execute an IGNORE command if the specified tube is not in the
  24. * cached watchlist.
  25. *
  26. * @param string $tube
  27. *
  28. * @return $this
  29. */
  30. public function ignore(string $tube): self;
  31. /**
  32. * Kicks buried or delayed jobs into a 'ready' state.
  33. * If there are buried jobs, it will kick up to $max of them.
  34. * Otherwise, it will kick up to $max delayed jobs.
  35. *
  36. * @param int $max The maximum jobs to kick
  37. *
  38. * @return int Number of jobs kicked
  39. */
  40. public function kick(int $max): int;
  41. /**
  42. * A variant of kick that operates with a single job. If the given job
  43. * exists and is in a buried or delayed state, it will be moved to the
  44. * ready queue of the the same tube where it currently belongs.
  45. */
  46. public function kickJob(JobIdInterface $job): void;
  47. /**
  48. * The names of all tubes on the server.
  49. *
  50. * @return string[]
  51. */
  52. public function listTubes(): array;
  53. /**
  54. * The names of the tubes being watched, to reserve jobs from.
  55. *
  56. * Returns the cached watchlist if $askServer is false (the default),
  57. * or queries the server for the watchlist if $askServer is true.
  58. *
  59. * @param bool $askServer
  60. *
  61. * @return string[]
  62. */
  63. public function listTubesWatched(bool $askServer = false): array;
  64. /**
  65. * The name of the current tube used for publishing jobs to.
  66. *
  67. * Returns the cached value if $askServer is false (the default),
  68. * or queries the server for the currently used tube if $askServer
  69. * is true.
  70. */
  71. public function listTubeUsed(bool $askServer = false): string;
  72. /**
  73. * Temporarily prevent jobs being reserved from the given tube.
  74. *
  75. * @param string $tube The tube to pause
  76. * @param int $delay Seconds before jobs may be reserved from this queue.
  77. */
  78. public function pauseTube(string $tube, int $delay): void;
  79. /**
  80. * Resume jobs for a given paused tube.
  81. * @param string $tube The tube to resume
  82. */
  83. public function resumeTube(string $tube): void;
  84. /**
  85. * Inspect a job in the system, regardless of what tube it is in.
  86. */
  87. public function peek(JobIdInterface $job): Job;
  88. /**
  89. * Inspect the next ready job in the currently used tube.
  90. */
  91. public function peekReady(): ?Job;
  92. /**
  93. * Inspect the shortest-remaining-delayed job in the currently used tube.
  94. * @return ?Job
  95. */
  96. public function peekDelayed(): ?Job;
  97. /**
  98. * Inspect the next job in the list of buried jobs in the currently used tube.
  99. */
  100. public function peekBuried(): ?Job;
  101. /**
  102. * Puts a job on the queue.
  103. *
  104. * @param string $data The job data
  105. * @param int $priority From 0 (most urgent) to 0xFFFFFFFF (least urgent)
  106. * @param int $delay Seconds to wait before job becomes ready
  107. * @param int $ttr Time To Run: seconds a job can be reserved for
  108. */
  109. public function put(
  110. string $data,
  111. int $priority = self::DEFAULT_PRIORITY,
  112. int $delay = self::DEFAULT_DELAY,
  113. int $ttr = self::DEFAULT_TTR
  114. ): Job;
  115. /**
  116. * Puts a reserved job back into the ready queue.
  117. *
  118. * Marks the jobs state as "ready" to be run by any client.
  119. * It is normally used when the job fails because of a transitory error.
  120. *
  121. * @param JobIdInterface $job
  122. * @param int $priority From 0 (most urgent) to 0xFFFFFFFF (least urgent)
  123. * @param int $delay Seconds to wait before job becomes ready
  124. */
  125. public function release(
  126. JobIdInterface $job,
  127. int $priority = self::DEFAULT_PRIORITY,
  128. int $delay = self::DEFAULT_DELAY
  129. ): void;
  130. /**
  131. * Reserves/locks a ready job in a watched tube.
  132. */
  133. public function reserve(): ?Job;
  134. /**
  135. * Reserves/locks a ready job in a watched tube, uses the 'reserve-with-timeout' instead of 'reserve'.
  136. *
  137. * A timeout value of 0 will cause the server to immediately return either a
  138. * response or TIMED_OUT. A positive value of timeout will limit the amount of
  139. * time the client will block on the reserve request until a job becomes
  140. * available.
  141. */
  142. public function reserveWithTimeout(int $timeout): ?Job;
  143. /**
  144. * Gives statistical information about the specified job if it exists.
  145. */
  146. public function statsJob(JobIdInterface $job): ResponseInterface;
  147. /**
  148. * Gives statistical information about the specified tube if it exists.
  149. */
  150. public function statsTube(string $tube): ResponseInterface;
  151. /**
  152. * Gives statistical information about the beanstalkd system as a whole.
  153. */
  154. public function stats(): ResponseInterface;
  155. /**
  156. * Allows a worker to request more time to work on a job.
  157. *
  158. * This is useful for jobs that potentially take a long time, but you still want
  159. * the benefits of a TTR pulling a job away from an unresponsive worker. A worker
  160. * may periodically tell the server that it's still alive and processing a job
  161. * (e.g. it may do this on DEADLINE_SOON).
  162. *
  163. */
  164. public function touch(JobIdInterface $job): void;
  165. /**
  166. * Change to the specified tube name for publishing jobs to.
  167. * This method would be called 'use' if it were not a PHP reserved word.
  168. *
  169. * Does not execute a USE command if the client is already using the
  170. * specified tube.
  171. *
  172. * @param string $tube
  173. *
  174. * @return $this
  175. */
  176. public function useTube(string $tube): self;
  177. /**
  178. * Add the specified tube to the watchlist, to reserve jobs from.
  179. *
  180. * Does not execute a WATCH command if the client is already watching the
  181. * specified tube.
  182. *
  183. * @param string $tube
  184. *
  185. * @return $this
  186. */
  187. public function watch(string $tube): self;
  188. /**
  189. * Adds the specified tube to the watchlist, to reserve jobs from, and
  190. * ignores any other tubes remaining on the watchlist.
  191. *
  192. * @param string $tube
  193. *
  194. * @return $this
  195. */
  196. public function watchOnly(string $tube): self;
  197. }