Solution:
<?php
namespace Drupal\my_custom_module1\Controller;
use Drupal\Core\Controller\ControllerBase;
class MyCustomClass123 extends ControllerBase
{
public function main()
{
// check if my process already running (started in the last 10 minutes / 600 seconds)
if( $this->my_custom_module1_check_if_process_running() == 1) {
return [
'#type' => 'inline_template',
'#template' => '{{ myhtml|raw }}',
'#context' => [ 'myhtml' => date(" Y-m-d H:i:s ") . "Duplicate : Another instance of this process is already running! "]
];
}
// if process not running execute code here
}
public function my_custom_module1_check_if_process_running(){
$my_custom_module1_process_last_timestamp = \Drupal::state()->get('my_custom_module1_process_last_timestamp') ?? 0;
if(time() - $my_custom_module1_process_last_timestamp) < 600){
// update / set system var
\Drupal::state()->set('my_custom_module1_process_last_timestamp', time() );
return 0;
}
return 1;
}
}
Neuen Kommentar schreiben