CronCommand.php
4.61 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
namespace Swpb\Bundle\CocarBundle\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
class CronCommand extends ContainerAwareCommand
{
/**
*
* @var type object
*/
private $em;
protected function configure()
{
$this
->setName('perform:task')
->setDescription('Run scheduled tasks')
->addOption(
'monitor',
null,
InputOption::VALUE_NONE
)
->addOption(
'status',
null,
InputOption::VALUE_NONE
)
->addOption(
'reliability',
null,
InputOption::VALUE_NONE
)
->addOption(
'rrdlog',
null,
InputOption::VALUE_NONE
)
->addOption(
'dailyperform',
null,
InputOption::VALUE_NONE
)
->addOption(
'generatealarm',
null,
InputOption::VALUE_NONE
)
->addOption(
'endalarm',
null,
InputOption::VALUE_NONE
)
->addOption(
'graphdailyperform',
null,
InputOption::VALUE_NONE
)
->addOption(
'printer',
null,
InputOption::VALUE_NONE
);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->em = $this->getContainer()->get('doctrine')->getManager();
//$this->getApplication()->getKernel()->getContainer()->get('doctrine')->getManager();
$return = null;
if ($input->getOption('monitor')) {
$return = $this->performTask('monitor');
}
elseif($input->getOption('status')) {
$return = $this->performTask('status');
}
elseif($input->getOption('reliability')) {
$return = $this->performTask('reliability');
}
elseif($input->getOption('rrdlog')) {
$return = $this->performTask('rrdlog');
}
elseif($input->getOption('dailyperform')) {
$return = $this->performTask('dailyperform');
}
elseif($input->getOption('generatealarm')) {
$return = $this->performTask('generatealarm');
}
elseif($input->getOption('endalarm')) {
$return = $this->performTask('endalarm');
}
elseif($input->getOption('graphdailyperform')) {
$return = $this->performTask('graphdailyperform');
}
elseif($input->getOption('printer')) {
$return = $this->performTask('printer');
}
$output->writeln($return);
}
private function performTask($task)
{
try
{
#$r = file_get_contents($this->getApplication()->getKernel()->getContainer()->get('router')
# ->generate("cocar_$task", array(), true));
if($task == 'monitor')
file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/monitor");
elseif($task == 'status')
file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/status");
elseif($task == 'reliability')
file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/reliability");
elseif($task == 'rrdlog')
file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/rrdlog");
elseif($task == 'dailyperform')
file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/dailyperform");
elseif($task == 'generatealarm')
file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/generatealarm");
elseif($task == 'endalarm')
file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/endalarm");
elseif($task == 'graphdailyperform')
file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/graphdailyperform");
elseif($task == 'printer')
$this->getContainer()->get('printer')->totalizer();
}
catch(Exception $e)
{
return "An unexpected: $task";
}
return "Task executed: $task";
}
}