Commit eaf2d52b authored by Joao Ventura's avatar Joao Ventura
Browse files

Revert "Issue #3133969 by kpa, mlemon, R0djer, jcnventura: Restore `timeout`...

Revert "Issue #3133969 by kpa, mlemon, R0djer, jcnventura: Restore `timeout` option for Drush command"

This reverts commit 93c2cbb7.
parent 93c2cbb7
Loading
Loading
Loading
Loading
+1 −12
Original line number Diff line number Diff line
@@ -48,18 +48,12 @@ class AdvancedQueueCommands extends DrushCommands {
   *
   * @param string $queue_id
   *   The queue ID.
   * @param array $options
   *   The options passed to this drush function.
   *
   * @throws \Exception
   *
   * @command advancedqueue:queue:process
   * @option timeout The maximum execution time of the script. Be warned that this is a rough estimate as the time is only checked between two items.
   * @usage advancedqueue:queue:process queuename --timeout=60
   *   Create a daemon-esque process for 60 seconds to process the
   *   {queuename} queue.  After this, the process will complete.
   */
  public function process($queue_id, array $options = ['timeout' => 90]) {
  public function process($queue_id) {
    $queue_storage = $this->entityTypeManager->getStorage('advancedqueue_queue');
    /** @var \Drupal\advancedqueue\Entity\QueueInterface $queue */
    $queue = $queue_storage->load($queue_id);
@@ -79,11 +73,6 @@ class AdvancedQueueCommands extends DrushCommands {
      });
    }

    // Set the processing time for this Drush command. Note: it is up to
    // Processor implementations to handle this. See the default
    // \Drupal\advancedqueue\Processor class for an example of this.
    $queue->setProcessingTime((int) $options['timeout']);

    $start = microtime(TRUE);
    $num_processed = $this->processor->processQueue($queue);
    $elapsed = microtime(TRUE) - $start;
+7 −9
Original line number Diff line number Diff line
@@ -96,20 +96,18 @@ class Processor implements ProcessorInterface {
      if ($this->shouldStop) {
        break;
      }

      if ($processing_time && $this->time->getCurrentTime() >= $expected_end) {
        // Time limit reached. Stop here.
        break;
      }

      $job = $queue->getBackend()->claimJob();
      if (!$job) {
        // No item processed in that round, let the CPU rest.
        sleep(1);
        continue;
        // The queue is empty. Stop here.
        break;
      }
      $this->processJob($job, $queue);
      $num_processed++;

      if ($processing_time && $this->time->getCurrentTime() >= $expected_end) {
        // Time limit reached. Stop here.
        break;
      }
    }

    return $num_processed;
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ use Drupal\advancedqueue\Plugin\AdvancedQueue\JobType\JobTypeBase;
 *   id = "retry",
 *   label = @Translation("Retry"),
 *   max_retries = 1,
 *   retry_delay = 5,
 *   retry_delay = 1,
 * )
 */
class Retry extends JobTypeBase {
+2 −3
Original line number Diff line number Diff line
@@ -108,7 +108,6 @@ class ProcessorTest extends KernelTestBase {
   * @dataProvider retryJobProvider
   */
  public function testRetry(Job $job) {
    $this->queue->setProcessingTime(2);
    $this->queue->enqueueJob($job);

    // Confirm that the job has been requeued.
@@ -122,7 +121,7 @@ class ProcessorTest extends KernelTestBase {
    $this->assertEquals(0, $num_processed);

    // Confirm that the job was re-processed, and left after the $retry_limit.
    sleep(5);
    sleep(1);
    $num_processed = $this->processor->processQueue($this->queue);
    $this->assertEquals(1, $num_processed);
    $counts = $this->queue->getBackend()->countJobs();
@@ -152,7 +151,7 @@ class ProcessorTest extends KernelTestBase {
      'expected_state' => Job::STATE_FAILURE,
      'expected_message' => '',
      'max_retries' => '1',
      'retry_delay' => 5,
      'retry_delay' => 1,
    ]);

    return [[$first_job], [$second_job]];