Commit 76a6cd9e authored by voleger's avatar voleger
Browse files

Initial commit

parents
queue_order.settings:
type: config_object
label: 'Queue Order config'
mapping:
order:
type: sequence
label: 'Queue order'
sequence:
- type: queue_order.settings.order.[%key]
queue_order.settings.order.*:
type: integer
label: 'Weight for % queue'
name: Queue order [no UI]
type: module
description: "Provide api to control queue order execution"
package: System utility
core: 8.x
dependencies:
- drupal:system (>= 8.2.0)
<?php
namespace Drupal\queue_order\Queue;
use Drupal\Component\Utility\SortArray;
use Drupal\Core\Queue\QueueWorkerManager as CoreQueueWorkerManager;
/**
* Class QueueWorkerManager.
*
* @package Drupal\queue_order\Queue
*/
class QueueWorkerManager extends CoreQueueWorkerManager {
/**
* {@inheritdoc}
*/
public function getDefinitions() {
$definitions = parent::getDefinitions();
$weight = \Drupal::config('queue_order.settings')->get('order');
$weight = empty($weight) ? [] : $weight;
foreach ($definitions as $key => &$definition) {
$definition['weight'] = empty($weight[$key]) ? 0 : intval($weight[$key]);
}
uasort($definitions, [SortArray::class, 'sortByWeightElement']);
return $definitions;
}
}
<?php
namespace Drupal\queue_order;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
use Drupal\queue_order\Queue\QueueWorkerManager;
/**
* Class QueueOrderServiceProvider.
*
* @package Drupal\queue_order
*/
class QueueOrderServiceProvider extends ServiceProviderBase {
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container) {
if ($container->has('plugin.manager.queue_worker')) {
$container->getDefinition('plugin.manager.queue_worker')
->setClass(QueueWorkerManager::class);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment