在 Drupal 8 中动态更改注释值

Dynamically change annotation value in Drupal 8

如何在 Drupal 8 中动态更改注释值?例如,我希望以下注释中的 cron = {"time" = 120}cron = {"time" = 600}。我想从配置中获得 600 或其他一些值。

/**
 * Updates the google analytics counters.
 *
 * @QueueWorker(
 *   id = "google_analytics_counter_worker",
 *   title = @Translation("Import Data from Google Analytics"),
 *   cron = {"time" = 120}
 * )
 */

我试过在注释前添加一个常量:

const DURATION = 600;

/**
 * Updates the google analytics counters.
 *
 * @QueueWorker(
 *   id = "google_analytics_counter_worker",
 *   title = @Translation("Import Data from Google Analytics"),
 *   cron = {"time" = DURATION}
 * )
 */

但是它抛出一个错误:

Doctrine\Common\Annotations\AnnotationException: [Semantical Error] Couldn't find constant DURATION, class                                                                [error]
Drupal\google_analytics_counter\Plugin\QueueWorker\GoogleAnalyticsCounterQueue. in
/private/var/www/sites/mskcc_deploy/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:54

为此使用 hook_queue_info_alter

function mymodule_queue_info_alter(&$queues) {
  $queues['google_analytics_counter_worker']['cron']['time'] = DURATION;
}