|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package: chapi |
|
4
|
|
|
* |
|
5
|
|
|
* @author: msiebeneicher |
|
6
|
|
|
* @since: 2015-07-30 |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Chapi\Commands; |
|
11
|
|
|
|
|
12
|
|
|
use Chapi\Service\JobRepository\JobRepositoryInterface; |
|
13
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
14
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
15
|
|
|
|
|
16
|
|
|
class InfoCommand extends AbstractCommand |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Configures the current command. |
|
20
|
|
|
*/ |
|
21
|
1 |
|
protected function configure() |
|
22
|
|
|
{ |
|
23
|
1 |
|
$this->setName('info') |
|
24
|
1 |
|
->setDescription('Display your job information from chronos') |
|
25
|
1 |
|
->addArgument('jobName', InputArgument::REQUIRED, 'selected job') |
|
26
|
|
|
; |
|
27
|
1 |
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @return int |
|
31
|
|
|
*/ |
|
32
|
1 |
|
protected function process() |
|
33
|
|
|
{ |
|
34
|
1 |
|
$jobName = $this->input->getArgument('jobName'); |
|
35
|
|
|
|
|
36
|
1 |
|
$chronosJobEntity = $this->checkInChronos($jobName); |
|
37
|
1 |
|
$jobEntity = $chronosJobEntity == null ? $this->checkInMarathon($jobName) : $chronosJobEntity; |
|
38
|
|
|
|
|
39
|
1 |
|
if (!$jobEntity) { |
|
40
|
|
|
$this->output->writeln(sprintf('<fg=red>%s</>', 'Could not find the job.')); |
|
41
|
|
|
return 1; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
1 |
|
$this->output->writeln(sprintf("\n<comment>info '%s'</comment>\n", $jobEntity->getKey())); |
|
45
|
|
|
|
|
46
|
1 |
|
$table = new Table($this->output); |
|
47
|
1 |
|
$table->setHeaders(array('Property', 'Value')); |
|
48
|
|
|
|
|
49
|
1 |
|
foreach ($jobEntity as $key => $value) { |
|
50
|
1 |
|
if (is_array($value) || is_object($value)) { |
|
51
|
1 |
|
$emptyString = (is_object($value)) ? '{ }' : '[ ]'; |
|
52
|
|
|
|
|
53
|
1 |
|
$value = (!empty($value)) |
|
54
|
|
|
? json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) |
|
55
|
1 |
|
: $emptyString; |
|
56
|
1 |
|
} elseif (is_bool($value)) { |
|
57
|
1 |
|
$value = (true === $value) |
|
58
|
1 |
|
? 'true' |
|
59
|
1 |
|
: 'false'; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
$table->addRow(array($key, $value)); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
1 |
|
$table->render(); |
|
66
|
|
|
|
|
67
|
1 |
|
return 0; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
1 |
|
private function checkInChronos($jobName) |
|
71
|
|
|
{ |
|
72
|
|
|
/** @var JobRepositoryInterface $jobRepositoryChronos */ |
|
73
|
1 |
|
$jobRepositoryChronos = $this->getContainer()->get(JobRepositoryInterface::DIC_NAME_CHRONOS); |
|
74
|
1 |
|
return $jobRepositoryChronos->getJob($jobName); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
private function checkInMarathon($jobName) |
|
78
|
|
|
{ |
|
79
|
|
|
/** @var JobRepositoryInterface $jobRepositoryMarathon */ |
|
80
|
|
|
$jobRepositoryMarathon = $this->getContainer()->get(JobRepositoryInterface::DIC_NAME_MARATHON); |
|
81
|
|
|
return $jobRepositoryMarathon->getJob($jobName); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|