Fix invalid closing of queues from sender, improve cleaning of pid files

This commit is contained in:
osaajani 2020-03-04 03:28:34 +01:00
parent 6f8c7d62b9
commit ca9397b62d
5 changed files with 14 additions and 17 deletions

View File

@ -25,6 +25,7 @@ then
if [ $RETURN -eq 0 ] if [ $RETURN -eq 0 ]
then then
rm -f "$DAEMON_LAUNCHER_PID_FILE"
printf "success.\n" printf "success.\n"
else else
printf "failed.\n" printf "failed.\n"
@ -42,6 +43,7 @@ do
printf "." printf "."
PID=$(cat "$f") PID=$(cat "$f")
kill_process "$PID" kill_process "$PID"
rm -f "$f"
done done
printf "Done.\n" printf "Done.\n"

View File

@ -53,7 +53,7 @@ namespace controllers\internals;
$phone = $internal_phone->get($id_phone); $phone = $internal_phone->get($id_phone);
if (!$phone) if (!$phone)
{ {
return false; exit(1);
} }
new \daemons\Phone($phone); new \daemons\Phone($phone);

View File

@ -328,7 +328,7 @@ namespace controllers\internals;
'id_user' => $scheduled['id_user'], 'id_user' => $scheduled['id_user'],
'id_scheduled' => $scheduled['id'], 'id_scheduled' => $scheduled['id'],
'id_phone' => $phone_to_use['id'], 'id_phone' => $phone_to_use['id'],
'destination' => $number['number'], 'destination' => $contact['number'],
'flash' => $scheduled['flash'], 'flash' => $scheduled['flash'],
]; ];

View File

@ -19,6 +19,7 @@ use Monolog\Logger;
*/ */
class Phone extends AbstractDaemon class Phone extends AbstractDaemon
{ {
private $max_inactivity = 5*60;
private $msg_queue; private $msg_queue;
private $msg_queue_id; private $msg_queue_id;
private $webhook_queue; private $webhook_queue;
@ -53,12 +54,7 @@ class Phone extends AbstractDaemon
public function run() public function run()
{ {
//Stop after 5 minutes of inactivity to avoid useless daemon usleep(0.5 * 1000000); //Micro sleep for perfs
if ((microtime(true) - $this->last_message_at) > 5 * 60)
{
posix_kill(getmypid(), SIGTERM); //Send exit signal to the current process
return false;
}
$this->bdd = \descartes\Model::_connect(DATABASE_HOST, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, 'UTF8'); $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 //Read received smss
$this->read_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() public function on_start()

View File

@ -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 * @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); 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']); $this->internal_scheduled->delete($sms['id_scheduled']);
} }
} }
@ -93,13 +94,6 @@ class Sender extends AbstractDaemon
public function on_stop() public function on_stop()
{ {
$this->logger->info('Stopping Sender with pid ' . getmypid()); $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) public function handle_other_signals($signal)