/**
  * Bootstrap method to be called during application bootstrap stage.
  *
  * @param Application $app the application currently running
  */
 public function bootstrap($app)
 {
     if ($app instanceof \yii\console\Application) {
         // add deferred module
         $app->setModule('deferred', new DeferredTasksModule('deferred', $app));
         // this will automatically add deferred controller to console app
         $app->controllerMap['deferred'] = ['class' => DeferredController::className()];
     }
     $app->i18n->translations['deferred-tasks'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => __DIR__ . DIRECTORY_SEPARATOR . 'messages'];
     DeferredQueueEvent::on(DeferredController::className(), DeferredController::EVENT_DEFERRED_QUEUE_COMPLETE, [QueueCompleteEventHandler::className(), 'handleEvent']);
 }
 public function testQueueCompleteEventHandler()
 {
     $files = ['task401', 'task402'];
     $testChain = new ReportingChain();
     foreach ($files as $f) {
         if (file_exists("/tmp/{$f}")) {
             unlink("/tmp/{$f}");
         }
         $testTask = new ReportingTask();
         $testTask->cliCommand('touch', ["/tmp/{$f}"]);
         $testChain->addTask($testTask);
     }
     $firstTaskId = $testChain->registerChain();
     DeferredHelper::runImmediateTask($firstTaskId);
     sleep(2);
     $this->assertTrue(file_exists('/tmp/task401'));
     /** @var DeferredQueue $queue */
     $queue = DeferredQueue::findOne(['id' => $firstTaskId]);
     $process = new Process('pwd > /dev/null');
     $process->run();
     $queue->setProcess($process);
     $event = new DeferredQueueCompleteEvent($queue);
     QueueCompleteEventHandler::handleEvent($event);
     sleep(2);
     $this->assertTrue(file_exists('/tmp/task402'));
 }