4
4
5
5
use Doctrine \DBAL \Connection ;
6
6
use Doctrine \DBAL \Types \Type ;
7
+ use Okvpn \Bundle \MQInsightBundle \Exception \TerminateCommandException ;
7
8
use Okvpn \Bundle \MQInsightBundle \Manager \ProcessManager ;
8
9
use Okvpn \Bundle \MQInsightBundle \Model \AppConfig ;
9
10
use Okvpn \Bundle \MQInsightBundle \Model \Provider \QueueProviderInterface ;
@@ -47,6 +48,7 @@ class StatRetrieveCommand extends ContainerAwareCommand
47
48
protected function configure ()
48
49
{
49
50
$ this ->setName (self ::NAME )
51
+ ->addArgument ('application ' , InputArgument::REQUIRED )
50
52
->addArgument ('parentPid ' , InputArgument::REQUIRED )
51
53
->addOption ('pollingInterval ' , null , InputOption::VALUE_OPTIONAL , 'The polling interval in sec. ' )
52
54
->setDescription ('Retrieve message count statistics ' );
@@ -91,7 +93,6 @@ protected function initialize(InputInterface $input, OutputInterface $output)
91
93
protected function execute (InputInterface $ input , OutputInterface $ output )
92
94
{
93
95
$ shmid = function_exists ('sem_get ' ) ? sem_get (AppConfig::getApplicationID ()) : null ;
94
-
95
96
if ($ shmid && !sem_acquire ($ shmid , true )) {
96
97
$ output ->writeln ('<info>Not allowed to run a more one command.</info> ' );
97
98
return 0 ;
@@ -103,9 +104,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
103
104
$ this ->delayPool ->sync ();
104
105
sleep (1 );
105
106
}
107
+ } catch (TerminateCommandException $ exception ) {
108
+ $ output ->writeln ('<error> ' . $ exception ->getMessage () .'</error> ' );
109
+ return 1 ;
106
110
} finally {
107
111
if ($ shmid ) {
108
- sem_release ($ shmid );
112
+ @sem_release ($ shmid );
113
+ @sem_remove ($ shmid );
109
114
}
110
115
}
111
116
@@ -136,16 +141,12 @@ protected function processCount()
136
141
protected function terminateIfNeeded ()
137
142
{
138
143
$ message = '' ;
139
- if (ProcessManager::getNumberOfRunningProcess (self ::NAME ) > 1 ) {
140
- $ message .= "Running more than one instance StatRetrieveCommand \n" ;
141
- }
142
-
143
144
if (ProcessManager::getProcessNameByPid ($ this ->parentPid ) === '' ) {
144
- $ message = "The parent process died. Parent pid not found: {$ this ->parentPid }\n" ;
145
+ $ message = "The parent process died. Parent pid not found: {$ this ->parentPid }\n" ;
145
146
}
146
147
147
148
if ($ message ) {
148
- throw new \ RuntimeException ($ message );
149
+ throw new TerminateCommandException ($ message );
149
150
}
150
151
}
151
152
}
0 commit comments