Commit 9a36a99d authored by Neil Drumm's avatar Neil Drumm 👋
Browse files

Issue #3267248: Hold sending packaging job if another is already sent or running for a project

parent 9e9e0176
Loading
Loading
Loading
Loading
+26 −6
Original line number Diff line number Diff line
@@ -5736,12 +5736,6 @@ function drupalorg_release_contents_hashes_process($item) {
 *   As well as the number of times we've attempted to send it ot jenkins.
 */
function drupalorg_packaging_pipeline_process($item) {
  if (empty($item['attempts'])) {
    $item['attempts'] = 1;
  }
  else {
    $item['attempts'] += 1;
  }
  // Takes the packaging job id, retreives the job from the db,
  // and sends the data to jenkins.

@@ -5750,6 +5744,32 @@ function drupalorg_packaging_pipeline_process($item) {
  $packaging_job = entity_load_single('drupalorg_packaging_job', $item['job_id']);

  try {
    // Check if there is a sent or running job with the same project.
    $same_project = (new EntityFieldQuery())->entityCondition('entity_type', 'drupalorg_packaging_job')
      ->propertyCondition('project_nid', $packaging_job->project_nid)
      ->propertyCondition('status', [DRUPALORG_JOB_STATUS_SENT, DRUPALORG_JOB_STATUS_RUNNING])
      ->range(0, 1)->execute();
    if (!empty($same_project)) {
      // If there is, hold processing.
      watchdog('drupalorg_packaging', 'Holding packaging @project @reference, another job for the project is in-progress.', [
        '@project' => $packaging_job->project_machine_name,
        '@reference' => $packaging_job->reference,
      ], WATCHDOG_NOTICE);
      $queue = DrupalQueue::get('drupalorg_packaging_pipeline');
      if ($queue instanceof BeanstalkdQueue) {
        $queue->beanstalkd_params['delay'] = variable_get('drupalorg_packaging_retry_delay', 60);
      }
      $queue->createItem($item);
      return;
    }

    if (empty($item['attempts'])) {
      $item['attempts'] = 1;
    }
    else {
      $item['attempts'] += 1;
    }

    // Task methods are expected to return TRUE if complete, FALSE if they can
    // not complete yet, or throw an Exception.
    if ($item['attempts'] > variable_get('drupalorg_packaging_pipeline_retrys', 15)) {