-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathExecuteCommand.php
More file actions
56 lines (43 loc) · 1.76 KB
/
ExecuteCommand.php
File metadata and controls
56 lines (43 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* This file is part of Temporal package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Temporal\Samples\Query;
use Carbon\CarbonInterval;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Temporal\Client\WorkflowOptions;
use Temporal\SampleUtils\Command;
class ExecuteCommand extends Command
{
protected const NAME = 'query';
protected const DESCRIPTION = 'Execute Query\QueryWorkflow with additional query and timer';
public function execute(InputInterface $input, OutputInterface $output): int
{
$workflow = $this->workflowClient->newWorkflowStub(
QueryWorkflowInterface::class,
WorkflowOptions::new()->withWorkflowExecutionTimeout(CarbonInterval::minute())
);
$output->writeln("Starting <comment>QueryWorkflow</comment>... ");
$run = $this->workflowClient->start($workflow, 'Antony');
$output->writeln(
sprintf(
'Started: WorkflowID=<fg=magenta>%s</fg=magenta>, RunID=<fg=magenta>%s</fg=magenta>',
$run->getExecution()->getID(),
$run->getExecution()->getRunID(),
)
);
$output->writeln("Querying <comment>QueryWorkflow->queryGreeting</comment>... ");
$output->writeln(sprintf("Query result:\n<info>%s</info>", $workflow->queryGreeting()));
$output->writeln("Sleeping for 2 seconds... ");
sleep(2);
$output->writeln(sprintf("Query result:\n<info>%s</info>", $workflow->queryGreeting()));
// wait for workflow to complete
$run->getResult();
return self::SUCCESS;
}
}