Skip to content

Commit

Permalink
allow workflow cmd to fial workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Nov 22, 2022
1 parent ac60e9c commit 6ca1fde
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions Command/WorkflowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Kaliop\eZWorkflowEngineBundle\Command;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Kaliop\eZMigrationBundle\API\Value\Migration;
use Kaliop\eZMigrationBundle\API\Value\MigrationDefinition;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Command to manipulate existing workflows.
Expand All @@ -28,16 +28,21 @@ protected function configure()
->setDescription('Manually delete workflows from the database table.')
->addOption('delete', null, InputOption::VALUE_NONE, "Delete the specified workflow.")
->addOption('info', null, InputOption::VALUE_NONE, "Get info about the specified workflow.")
->addOption('fail', null, InputOption::VALUE_NONE, "Mark the specified migration as failed.")
->addOption('no-interaction', 'n', InputOption::VALUE_NONE, "Do not ask any interactive question.")
->addArgument('workflow', InputArgument::REQUIRED, 'The workflow to view or delete (plain workflow name).', null)
->setHelp(<<<EOT
The <info>kaliop:workflows:workflow</info> command allows you to manually delete dead workflows from the database table:
The <info>kaliop:workflows:workflow</info> command allows you to manually manage workflows in the database table.
To see detailed information about a workflow:
<info>./ezpublish/console kaliop:workflows:workflow --delete workflow_name</info>
<info>php bin/console kaliop:workflows:workflow --info workflow_name</info>
As well as viewing details:
To remove a workflow from the workflow table, or mark it as failed:
<info>./ezpublish/console kaliop:workflows:workflow --info workflow_name</info>
<info>php bin/console kaliop:workflows:workflow --delete workflow_name</info>
<info>php bin/console kaliop:workflows:workflow --fail workflow_name</info>
EOT
);
}
Expand All @@ -51,8 +56,8 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!$input->getOption('delete') && !$input->getOption('info')) {
throw new \InvalidArgumentException('You must specify whether you want to --delete or --info the specified workflow.');
if (!$input->getOption('delete') && !$input->getOption('info') && !$input->getOption('fail')) {
throw new \InvalidArgumentException('You must specify whether you want to --delete, --fail or --info the specified workflow.');
}

$workflowService = $this->getWorkflowService();
Expand Down Expand Up @@ -137,7 +142,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$output->writeln('');
return;
return 0;
}

// ask user for confirmation to make changes
Expand All @@ -154,15 +159,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

if ($input->getOption('delete')) {
if ($input->getOption('delete') || $input->getOption('fail')) {
$workflow = $workflowService->getWorkflow($workflowNameOrPath);
if ($workflow == null) {
throw new \InvalidArgumentException(sprintf('The workflow "%s" does not exist in the database table.', $workflowNameOrPath));
}

$workflowService->deleteWorkflow($workflow);
if ($input->getOption('delete')) {
$workflowService->deleteWorkflow($workflow);
} else {
$errorMessage = 'Manually failed on ' . date("Y-m-d H:i:s");
if ($workflow->executionError != '') {
$errorMessage .= ". Previous notes: " . $workflow->executionError;
}
$workflowService->failWorkflow($workflow, $errorMessage);
}

return;
return 0;
}
}
}

0 comments on commit 6ca1fde

Please sign in to comment.