Commit 9ca1e055 authored by voleger's avatar voleger Committed by voleger
Browse files

Issue #2962017 by voleger: Do not force `cron` key to be defined

parent 6ce09b77
......@@ -61,10 +61,16 @@ class QueueWorkerManager extends CoreQueueWorkerManager {
public static function sortDefinitions(array $definitions, array $weight) {
// Prepare definitions for sorting.
foreach ($definitions as $key => &$definition) {
$weight = 0;
// Define default weight value or hint defined weight to the int value.
$definition['cron']['weight'] = empty($definition['cron']['weight']) ? 0 : intval($definition['cron']['weight']);
if (!empty($definition['cron']['weight'])) {
$weight = intval($definition['cron']['weight']);
}
if (!empty($definition['weight'])) {
$weight = intval($definition['weight']);
}
// Check weight value overrides.
$definition['weight'] = empty($weight[$key]) ? $definition['cron']['weight'] : intval($weight[$key]);
$definition['weight'] = empty($weight[$key]) ? $weight : intval($weight[$key]);
}
// Sort definitions by weight element.
uasort($definitions, [SortArray::class, 'sortByWeightElement']);
......
......@@ -27,4 +27,13 @@ class DefinitionsWithModuleTest extends DefinitionsWithoutModuleTest {
);
}
/**
* Test is functionality force creation of `cron` key.
*/
public function testCronKeyExistance() {
$definition = $this->QueueWorkerManager
->getDefinition('queue_order_worker_B');
$this->assertArrayNotHasKey('cron', $definition);
}
}
......@@ -10,7 +10,7 @@ namespace Drupal\queue_order_definition_fixtures\Plugin\QueueWorker;
* @QueueWorker(
* id="queue_order_worker_B",
* title="Test worker with '1' position",
* cron={"time" = 60, "weight" = -50,}
* weight=-50
* )
*/
class WorkerB extends WorkerBase {}
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