2222 */
2323class SchedulerCommandController extends CommandController
2424{
25+ private const TEN_MINUTES_IN_SECONDS = 600 ;
26+
27+ protected $ stopPollingAfter = self ::TEN_MINUTES_IN_SECONDS ;
28+
2529 /**
2630 * @var Scheduler
2731 */
@@ -77,11 +81,10 @@ public function queueDueJobsCommand(string $groupName): void
7781 public function pollForIncomingJobsCommand (string $ groupName ): void
7882 {
7983 $ startTime = time ();
80- $ oneHourInSeconds = 3600 ;
81- $ endTime = $ startTime + $ oneHourInSeconds ;
84+ $ endTime = $ startTime + $ this ->stopPollingAfter ;
8285
8386 while (true ) {
84- $ numberOfHandledJobs = $ this ->queueDueJobs ($ groupName );
87+ $ numberOfHandledJobs = $ this ->queueDueJobs ($ groupName, $ endTime );
8588 if (time () >= $ endTime ) {
8689 return ;
8790 }
@@ -92,9 +95,12 @@ public function pollForIncomingJobsCommand(string $groupName): void
9295 }
9396
9497 /**
98+ * @param string $groupName Handle only jobs of this group
99+ * @param int $endTime Stop handling new jobs once this time is reached
95100 * @return int Number of handled jobs
101+ * @throws ConnectionLost
96102 */
97- protected function queueDueJobs (string $ groupName ): int
103+ protected function queueDueJobs (string $ groupName, int $ endTime ): int
98104 {
99105 $ numberOfHandledJobs = 0 ;
100106 $ retry = new Retry ($ this ->scheduler );
@@ -116,6 +122,9 @@ protected function queueDueJobs(string $groupName): int
116122 $ this ->throwableStorage ->logThrowable ($ throwable );
117123 $ retry ->markJobForRescheduling ($ next );
118124 }
125+ if (time () >= $ endTime ) {
126+ return $ numberOfHandledJobs ;
127+ }
119128 }
120129
121130 $ retry ->scheduleAll ();
0 commit comments