Fix invalid closing of queues from sender, improve cleaning of pid files
This commit is contained in:
parent
6f8c7d62b9
commit
ca9397b62d
|
@ -25,6 +25,7 @@ then
|
|||
|
||||
if [ $RETURN -eq 0 ]
|
||||
then
|
||||
rm -f "$DAEMON_LAUNCHER_PID_FILE"
|
||||
printf "success.\n"
|
||||
else
|
||||
printf "failed.\n"
|
||||
|
@ -42,6 +43,7 @@ do
|
|||
printf "."
|
||||
PID=$(cat "$f")
|
||||
kill_process "$PID"
|
||||
rm -f "$f"
|
||||
done
|
||||
printf "Done.\n"
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace controllers\internals;
|
|||
$phone = $internal_phone->get($id_phone);
|
||||
if (!$phone)
|
||||
{
|
||||
return false;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
new \daemons\Phone($phone);
|
||||
|
|
|
@ -328,7 +328,7 @@ namespace controllers\internals;
|
|||
'id_user' => $scheduled['id_user'],
|
||||
'id_scheduled' => $scheduled['id'],
|
||||
'id_phone' => $phone_to_use['id'],
|
||||
'destination' => $number['number'],
|
||||
'destination' => $contact['number'],
|
||||
'flash' => $scheduled['flash'],
|
||||
];
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ use Monolog\Logger;
|
|||
*/
|
||||
class Phone extends AbstractDaemon
|
||||
{
|
||||
private $max_inactivity = 5*60;
|
||||
private $msg_queue;
|
||||
private $msg_queue_id;
|
||||
private $webhook_queue;
|
||||
|
@ -53,12 +54,7 @@ class Phone extends AbstractDaemon
|
|||
|
||||
public function run()
|
||||
{
|
||||
//Stop after 5 minutes of inactivity to avoid useless daemon
|
||||
if ((microtime(true) - $this->last_message_at) > 5 * 60)
|
||||
{
|
||||
posix_kill(getmypid(), SIGTERM); //Send exit signal to the current process
|
||||
return false;
|
||||
}
|
||||
usleep(0.5 * 1000000); //Micro sleep for perfs
|
||||
|
||||
$this->bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8');
|
||||
|
||||
|
@ -68,7 +64,12 @@ class Phone extends AbstractDaemon
|
|||
//Read received smss
|
||||
$this->read_smss();
|
||||
|
||||
usleep(0.5 * 1000000);
|
||||
//Stop after 5 minutes of inactivity to avoid useless daemon
|
||||
if ((microtime(true) - $this->last_message_at) > $this->max_inactivity)
|
||||
{
|
||||
posix_kill(getmypid(), SIGTERM); //Send exit signal to the current process
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function on_start()
|
||||
|
|
|
@ -54,7 +54,7 @@ class Sender extends AbstractDaemon
|
|||
}
|
||||
|
||||
/**
|
||||
* Function to get messages to send and transfer theme to phones daemons.
|
||||
* Function to transfer smss to send to phones daemons.
|
||||
*
|
||||
* @param array $smss : Smss to send
|
||||
*/
|
||||
|
@ -80,6 +80,7 @@ class Sender extends AbstractDaemon
|
|||
|
||||
msg_send($this->queues[$queue_id], QUEUE_TYPE_SEND_MSG, $msg);
|
||||
|
||||
$this->logger->info('Transmit sms send signal to phone ' . $sms['id_phone'] . ' on queue ' . $queue_id . '.');
|
||||
$this->internal_scheduled->delete($sms['id_scheduled']);
|
||||
}
|
||||
}
|
||||
|
@ -93,13 +94,6 @@ class Sender extends AbstractDaemon
|
|||
public function on_stop()
|
||||
{
|
||||
$this->logger->info('Stopping Sender with pid ' . getmypid());
|
||||
|
||||
//Delete queues on daemon close
|
||||
foreach ($this->queues as $queue_id => $queue)
|
||||
{
|
||||
$this->logger->info('Closing queue : ' . $queue_id);
|
||||
msg_remove_queue($queue);
|
||||
}
|
||||
}
|
||||
|
||||
public function handle_other_signals($signal)
|
||||
|
|
Loading…
Reference in New Issue