diff --git a/config/schema/strawberryfield.schema.yml b/config/schema/strawberryfield.schema.yml index 3b6a4a3..3c97833 100644 --- a/config/schema/strawberryfield.schema.yml +++ b/config/schema/strawberryfield.schema.yml @@ -219,7 +219,10 @@ strawberryfield.hydroponics_settings: mapping: active: type: boolean - label: If Hydroponics Service is enabled or not + label: 'If Hydroponics Service is enabled or not' + time_to_expire: + type: integer + label: 'How long Hydroponics Service should stay awake, 0 means until done with all queues' drush_path: type: string label: 'Full system path to the /vendor composer Drush installation including drush script' diff --git a/src/Commands/HydroponicsDrushCommands.php b/src/Commands/HydroponicsDrushCommands.php index 6fd024e..b2d1b17 100644 --- a/src/Commands/HydroponicsDrushCommands.php +++ b/src/Commands/HydroponicsDrushCommands.php @@ -11,7 +11,7 @@ use Drush\Commands\DrushCommands; use Drush\Exec\ExecTrait; use Drush\Runtime\Runtime; -use React\EventLoop\Factory; +use React\EventLoop\Loop; /** @@ -37,7 +37,7 @@ class HydroponicsDrushCommands extends DrushCommands { public function hydroponics( ) { - $loop = Factory::create(); + $loop = Loop::get(); $timer_ping = $loop->addPeriodicTimer(3.0, function () { // store a heartbeat every 3 seconds. $currenttime = \Drupal::time()->getCurrentTime(); @@ -106,22 +106,30 @@ public function hydroponics( \Drupal::logger('hydroponics')->info("All queues are idle, closing timers"); $loop->cancelTimer($timer); + $loop->stop(); } } ); - - $securitytimer = $loop->addTimer(720.0, function ($timer) use ($loop, $timer_ping, $idle_timer, &$done) { - // Finish all if 720 seconds are reached - \Drupal::logger('hydroponics')->info("720 seconds passed closing Hydroponics Service"); - $loop->cancelTimer($timer_ping); - foreach($done as $queue_timer) { - $loop->cancelTimer($queue_timer); - } - \Drupal::state()->set('hydroponics.queurunner_last_pid', 0); - $loop->cancelTimer($idle_timer); - $loop->stop(); - } - ); + $time_to_expire = (int) \Drupal::config('strawberryfield.hydroponics_settings')->get('time_to_expire'); + if ($time_to_expire > 0 ) { + $time_to_expire = round($time_to_expire, 1); + $securitytimer = $loop->addTimer($time_to_expire, + function ($timer) use ($loop, $timer_ping, $idle_timer, &$done, $time_to_expire) { + // Finish all if Time to live in seconds is reached + \Drupal::logger('hydroponics') + ->info("@time_to_expire seconds passed closing Hydroponics Service", [ + '@time_to_expire' => $time_to_expire, + ]); + $loop->cancelTimer($timer_ping); + foreach ($done as $queue_timer) { + $loop->cancelTimer($queue_timer); + } + \Drupal::state()->set('hydroponics.queurunner_last_pid', 0); + $loop->cancelTimer($idle_timer); + $loop->stop(); + } + ); + } /* TODO recompile with PCNTL enabled \pcntl_signal(SIGINT, 'signalhandler'); diff --git a/src/Form/HydroponicsSettingsForm.php b/src/Form/HydroponicsSettingsForm.php index a993478..072dcb9 100644 --- a/src/Form/HydroponicsSettingsForm.php +++ b/src/Form/HydroponicsSettingsForm.php @@ -133,6 +133,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('strawberryfield.hydroponics_settings'); $active = $config->get('active') ? $config->get('active') : FALSE; + $time_to_expire = $config->get('time_to_expire') !== null ? $config->get('time_to_expire') : 720; $drush_path = $config->get('drush_path') ? $config->get('drush_path') : NULL; $home_path = $config->get('home_path') ? $config->get('home_path') : NULL; $enabled_queues = !empty($config->get('queues')) ? array_flip($config->get('queues')) : []; @@ -177,6 +178,17 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#required' => FALSE, '#default_value' => $active, ]; + + $form['time_to_expire'] = [ + '#title' => 'Time to live (stay awake) for the Hydroponics Service.', + '#description' => 'A value of 0 will force the Service to finish all pending queues before shutting down', + '#type' => 'number', + '#step' => 60, + '#min' => 0, + '#required' => TRUE, + '#default_value' => $time_to_expire, + ]; + $form['advanced'] = [ '#type' => 'details', '#title' => 'Advanced settings', @@ -307,6 +319,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $global_active = (bool) $form_state->getValue('active'); $drush_path = rtrim($form_state->getValue('drush_path'), '/'); $home_path = rtrim($form_state->getValue('home_path'), '/'); + $time_to_expire = (int) trim($form_state->getValue('time_to_expire', 720)); foreach($form_state->getValue('table-row') as $queuename => $queue) { if ($queue['active'] == 1) { $enabled[] = $queuename; @@ -318,6 +331,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { ->set('drush_path', $drush_path) ->set('home_path', $home_path) ->set('queues', $enabled) + ->set('time_to_expire', $time_to_expire) ->save(); parent::submitForm($form, $form_state); } diff --git a/src/Plugin/Action/StrawberryfieldJsonPatch.php b/src/Plugin/Action/StrawberryfieldJsonPatch.php index 3423866..5975fb1 100644 --- a/src/Plugin/Action/StrawberryfieldJsonPatch.php +++ b/src/Plugin/Action/StrawberryfieldJsonPatch.php @@ -281,6 +281,14 @@ public function execute($entity = NULL) { ]); if (!$this->configuration['simulate']) { + if ($entity->getEntityType()->isRevisionable()) { + // Forces a New Revision for Not-create Operations. + $entity->setNewRevision(TRUE); + $entity->setRevisionCreationTime(\Drupal::time()->getRequestTime()); + // Set data for the revision + $entity->setRevisionLogMessage('ADO modified via JSON Patch Search And Replace with Patch:'. $this->configuration['jsonpatch']); + $entity->setRevisionUserId($this->currentUser->id()); + } $entity->save(); } }