mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-22 09:26:27 +02:00
Compare commits
2 commits
ea744d31e2
...
ad1f798ae6
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ad1f798ae6 | ||
![]() |
3dd5e099e8 |
4 changed files with 25 additions and 25 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
v3.5.2
|
v3.5.4
|
||||||
|
|
|
@ -23,7 +23,6 @@ class Phone extends AbstractDaemon
|
||||||
private $read_delay = 20 / 0.5;
|
private $read_delay = 20 / 0.5;
|
||||||
private $read_tick = 0;
|
private $read_tick = 0;
|
||||||
private $msg_queue;
|
private $msg_queue;
|
||||||
private $msg_queue_id;
|
|
||||||
private $webhook_queue;
|
private $webhook_queue;
|
||||||
private $last_message_at;
|
private $last_message_at;
|
||||||
private $phone;
|
private $phone;
|
||||||
|
@ -38,7 +37,6 @@ class Phone extends AbstractDaemon
|
||||||
public function __construct(array $phone)
|
public function __construct(array $phone)
|
||||||
{
|
{
|
||||||
$this->phone = $phone;
|
$this->phone = $phone;
|
||||||
$this->msg_queue_id = (int) (QUEUE_ID_PHONE_PREFIX . $this->phone['id']);
|
|
||||||
|
|
||||||
$name = 'RaspiSMS Daemon Phone ' . $this->phone['id'];
|
$name = 'RaspiSMS Daemon Phone ' . $this->phone['id'];
|
||||||
$logger = new Logger($name);
|
$logger = new Logger($name);
|
||||||
|
@ -87,7 +85,7 @@ class Phone extends AbstractDaemon
|
||||||
//Set last message at to construct time
|
//Set last message at to construct time
|
||||||
$this->last_message_at = microtime(true);
|
$this->last_message_at = microtime(true);
|
||||||
|
|
||||||
$this->msg_queue = msg_get_queue($this->msg_queue_id);
|
$this->msg_queue = msg_get_queue(QUEUE_ID_PHONE);
|
||||||
|
|
||||||
//Instanciate adapter
|
//Instanciate adapter
|
||||||
$adapter_class = $this->phone['adapter'];
|
$adapter_class = $this->phone['adapter'];
|
||||||
|
@ -98,10 +96,6 @@ class Phone extends AbstractDaemon
|
||||||
|
|
||||||
public function on_stop()
|
public function on_stop()
|
||||||
{
|
{
|
||||||
//Delete queue on daemon close
|
|
||||||
$this->logger->info('Closing queue : ' . $this->msg_queue_id);
|
|
||||||
msg_remove_queue($this->msg_queue);
|
|
||||||
|
|
||||||
$this->logger->info('Stopping Phone daemon with pid ' . getmypid());
|
$this->logger->info('Stopping Phone daemon with pid ' . getmypid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,8 +119,10 @@ class Phone extends AbstractDaemon
|
||||||
$maxsize = 409600;
|
$maxsize = 409600;
|
||||||
$message = null;
|
$message = null;
|
||||||
|
|
||||||
|
// Message type is forged from a prefix concat with the phone ID
|
||||||
|
$message_type = (int) QUEUE_TYPE_SEND_MSG_PREFIX . $this->phone['id'];
|
||||||
$error_code = null;
|
$error_code = null;
|
||||||
$success = msg_receive($this->msg_queue, QUEUE_TYPE_SEND_MSG, $msgtype, $maxsize, $message, true, MSG_IPC_NOWAIT, $error_code); //MSG_IPC_NOWAIT == dont wait if no message found
|
$success = msg_receive($this->msg_queue, $message_type, $msgtype, $maxsize, $message, true, MSG_IPC_NOWAIT, $error_code); //MSG_IPC_NOWAIT == dont wait if no message found
|
||||||
|
|
||||||
if (!$success && MSG_ENOMSG !== $error_code)
|
if (!$success && MSG_ENOMSG !== $error_code)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Sender extends AbstractDaemon
|
||||||
private $internal_scheduled;
|
private $internal_scheduled;
|
||||||
private $internal_received;
|
private $internal_received;
|
||||||
private $bdd;
|
private $bdd;
|
||||||
private $queues = [];
|
private $msg_queue;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -61,16 +61,15 @@ class Sender extends AbstractDaemon
|
||||||
public function transmit_smss(array $smss_per_scheduled): void
|
public function transmit_smss(array $smss_per_scheduled): void
|
||||||
{
|
{
|
||||||
foreach ($smss_per_scheduled as $id_scheduled => $smss)
|
foreach ($smss_per_scheduled as $id_scheduled => $smss)
|
||||||
{
|
|
||||||
foreach ($smss as $sms)
|
|
||||||
{
|
{
|
||||||
//If queue not already exists
|
//If queue not already exists
|
||||||
$queue_id = (int) (QUEUE_ID_PHONE_PREFIX . $sms['id_phone']);
|
if (!msg_queue_exists(QUEUE_ID_PHONE) || !isset($this->queue))
|
||||||
if (!msg_queue_exists($queue_id) || !isset($queues[$queue_id]))
|
|
||||||
{
|
{
|
||||||
$this->queues[$queue_id] = msg_get_queue($queue_id);
|
$this->msg_queue = msg_get_queue(QUEUE_ID_PHONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($smss as $sms)
|
||||||
|
{
|
||||||
$msg = [
|
$msg = [
|
||||||
'id_user' => $sms['id_user'],
|
'id_user' => $sms['id_user'],
|
||||||
'id_scheduled' => $sms['id_scheduled'],
|
'id_scheduled' => $sms['id_scheduled'],
|
||||||
|
@ -82,8 +81,10 @@ class Sender extends AbstractDaemon
|
||||||
'medias' => $sms['medias'] ?? [],
|
'medias' => $sms['medias'] ?? [],
|
||||||
];
|
];
|
||||||
|
|
||||||
msg_send($this->queues[$queue_id], QUEUE_TYPE_SEND_MSG, $msg);
|
// Message type is forged from a prefix concat with the phone ID
|
||||||
$this->logger->info('Transmit sms send signal to phone ' . $sms['id_phone'] . ' on queue ' . $queue_id . '.');
|
$message_type = (int) QUEUE_TYPE_SEND_MSG_PREFIX . $sms['id_phone'];
|
||||||
|
msg_send($this->msg_queue, $message_type, $msg);
|
||||||
|
$this->logger->info('Transmit sms send signal to phone ' . $sms['id_phone'] . ' on queue ' . QUEUE_ID_PHONE . ' with message type ' . $message_type . '.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->logger->info('Scheduled ' . $id_scheduled . ' treated and deleted.');
|
$this->logger->info('Scheduled ' . $id_scheduled . ' treated and deleted.');
|
||||||
|
@ -99,6 +100,10 @@ class Sender extends AbstractDaemon
|
||||||
|
|
||||||
public function on_stop()
|
public function on_stop()
|
||||||
{
|
{
|
||||||
|
//Delete queue on daemon close
|
||||||
|
$this->logger->info('Closing queue : ' . $this->msg_queue);
|
||||||
|
msg_remove_queue($this->msg_queue);
|
||||||
|
|
||||||
$this->logger->info('Stopping Sender with pid ' . getmypid());
|
$this->logger->info('Stopping Sender with pid ' . getmypid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,17 +53,16 @@
|
||||||
],
|
],
|
||||||
|
|
||||||
//Phone messages types
|
//Phone messages types
|
||||||
'QUEUE_ID_PHONE_PREFIX' => ftok(__FILE__, 'p'),
|
'QUEUE_ID_PHONE' => ftok(__FILE__, 'p'),
|
||||||
'QUEUE_TYPE_SEND_MSG' => 1,
|
'QUEUE_TYPE_SEND_MSG_PREFIX' => 100,
|
||||||
'QUEUE_TYPE_RECEIVE_MSG' => 2,
|
|
||||||
|
|
||||||
//Queues ids
|
//Queues ids
|
||||||
'QUEUE_ID_WEBHOOK' => ftok(__FILE__, 'w'),
|
'QUEUE_ID_WEBHOOK' => ftok(__FILE__, 'w'),
|
||||||
'QUEUE_TYPE_WEBHOOK' => 3,
|
'QUEUE_TYPE_WEBHOOK' => 100,
|
||||||
|
|
||||||
//Queue email
|
//Queue email
|
||||||
'QUEUE_ID_EMAIL' => ftok(__FILE__, 'e'),
|
'QUEUE_ID_EMAIL' => ftok(__FILE__, 'e'),
|
||||||
'QUEUE_TYPE_EMAIL' => 3,
|
'QUEUE_TYPE_EMAIL' => 100,
|
||||||
|
|
||||||
//User default settings
|
//User default settings
|
||||||
'USER_DEFAULT_SETTINGS' => [
|
'USER_DEFAULT_SETTINGS' => [
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue