advancedqueue-8.x-1.x-dev/advancedqueue.install

advancedqueue.install
<?php

/**
 * @file
 * Contains install and update functions for Advanced queue.
 */

use Drupal\Core\Database\Database;

/**
 * Implements hook_schema().
 */
function advancedqueue_schema() {
  $schema['advancedqueue'] = [
    'description' => 'Stores jobs in queues.',
    'fields' => [
      'job_id' => [
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary Key: Job ID.',
      ],
      'queue_id' => [
        'type' => 'varchar_ascii',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The queue ID.',
      ],
      'type' => [
        'type' => 'varchar_ascii',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The job type.',
      ],
      'payload' => [
        'type' => 'blob',
        'not null' => TRUE,
        'size' => 'big',
        'description' => 'The job payload, stored as JSON.',
      ],
      'state' => [
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'description' => 'The job state.',
      ],
      'message' => [
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'medium',
        'description' => 'The job message, stored after processing the job.',
      ],
      'num_retries' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'small',
        'description' => 'The number of times the job has been retried.',
      ],
      'available' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The availability timestamp.',
      ],
      'processed' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The processing timestamp.',
      ],
      'expires' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The lease expiration timestamp.',
      ],
      'fingerprint' => [
        'type' => 'varchar_ascii',
        'length' => 255,
        'not null' => FALSE,
        'description' => 'The unique hash of the job item.',
      ],
    ],
    'primary key' => ['job_id'],
    'indexes' => [
      'queue' => ['queue_id', 'state', 'available', 'expires'],
      'queue_state' => ['state'],
      'queue_expires' => ['expires'],
      'fingerprint' => ['fingerprint'],
      'queue_processed' => ['processed'],
      'type' => ['type'],
    ],
  ];

  return $schema;
}

/**
 * Add an index to the state column.
 */
function advancedqueue_update_8101(): void {
  $spec = advancedqueue_schema();
  $schema = Database::getConnection()->schema();
  $schema->addIndex('advancedqueue', 'queue_state', ['state'], $spec['advancedqueue']);
}

/**
 * Add an index to the expires column.
 */
function advancedqueue_update_8102(): void {
  $spec = advancedqueue_schema();
  $schema = Database::getConnection()->schema();
  $schema->addIndex('advancedqueue', 'queue_expires', ['expires'], $spec['advancedqueue']);
}

/**
 * Add an index to the processed column.
 */
function advancedqueue_update_8103(): void {
  $spec = advancedqueue_schema();
  $schema = Database::getConnection()->schema();
  $schema->addIndex('advancedqueue', 'queue_processed', ['processed'], $spec['advancedqueue']);
}

/**
 * Add fingerprint column and index.
 */
function advancedqueue_update_8104(): void {
  $spec = advancedqueue_schema();
  $schema = \Drupal::database()->schema();
  if (!$schema->fieldExists('advancedqueue', 'fingerprint')) {
    $schema->addField('advancedqueue', 'fingerprint', $spec['advancedqueue']['fields']['fingerprint']);
    $schema->addIndex('advancedqueue', 'fingerprint', ['fingerprint'], $spec['advancedqueue']);
  }
}

/**
 * Add an index on the "type" column.
 */
function advancedqueue_update_8105(): void {
  $spec = advancedqueue_schema();
  $schema = \Drupal::database()->schema();
  if (!$schema->indexExists('advancedqueue', 'type')) {
    $schema->addIndex('advancedqueue', 'type', ['type'], $spec['advancedqueue']);
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc