Skip to content

Commit

Permalink
Add Aeron check because of Fatal error
Browse files Browse the repository at this point in the history
Aeron send ping to publishers, and try to connect every second
  • Loading branch information
kleninmaxim committed May 25, 2022
1 parent fd5715c commit 2c879e9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
7 changes: 4 additions & 3 deletions kernel/balancer_by_market_order.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use robotrade\Api;
use Src\Aeron;
use Src\Configurator;
use Src\Core;
use Src\Gate;
Expand All @@ -23,9 +24,9 @@
// API для формирования сообщения для отправки по aeron
$robotrade_api = new Api($common_config['exchange'], $common_config['algorithm'], $common_config['node'], $common_config['instance']);

// нужен publisher, отправлять команды по aeron в гейт
$publisher = new Publisher($config['aeron']['publishers']['gate']['channel'], $config['aeron']['publishers']['gate']['stream_id']);
sleep(1);
Aeron::checkConnection(
$publisher = new Publisher($config['aeron']['publishers']['gate']['channel'], $config['aeron']['publishers']['gate']['stream_id'])
);

// класс для работы с гейтом
$gate = new Gate($publisher, $robotrade_api, $common_config['gate_sleep'] ?? 0);
Expand Down
6 changes: 4 additions & 2 deletions kernel/cross_3t.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use robotrade\Api;
use Src\Aeron;
use Src\Configurator;
use Src\Core;
use Src\Gate;
Expand All @@ -26,8 +27,9 @@
$robotrade_api = new Api($common_config['exchange'], $common_config['algorithm'], $common_config['node'], $common_config['instance']);

// нужен publisher, отправлять команды по aeron в гейт
$publisher = new Publisher($config['aeron']['publishers']['gate']['channel'], $config['aeron']['publishers']['gate']['stream_id']);
sleep(1);
Aeron::checkConnection(
$publisher = new Publisher($config['aeron']['publishers']['gate']['channel'], $config['aeron']['publishers']['gate']['stream_id'])
);

// создаем класс cross 3t
$cross_3t = new Cross3T($config, $common_config);
Expand Down
11 changes: 6 additions & 5 deletions kernel/receive_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@

$log = new Log($common_config['exchange'], $common_config['algorithm'], $common_config['node'], $common_config['instance']);

}
// нужен publisher, отправлять логи на сервер логов
Aeron::checkConnection(
$publisher = new Publisher($config['aeron']['publishers']['log']['channel'], $config['aeron']['publishers']['log']['stream_id'])
);

// нужен publisher, отправлять логи на сервер логов
$publisher = new Publisher($config['aeron']['publishers']['log']['channel'], $config['aeron']['publishers']['log']['stream_id']);
sleep(1);
}

function handler_orderbooks(string $message): void
{
Expand Down Expand Up @@ -123,7 +124,7 @@ function handler_balances(string $message): void

$subscriber_balances->poll();

if ($common_config['send_ping_to_log_server'] && isset($discrete_time) && isset($log) && $discrete_time->proof()) {
if ($common_config['send_ping_to_log_server'] && isset($publisher) && isset($discrete_time) && isset($log) && $discrete_time->proof()) {

if (isset($i)) {
$i++;
Expand Down
28 changes: 28 additions & 0 deletions src/Aeron.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Src;

use Aeron\Publisher;
use Exception;

class Aeron
{

Expand All @@ -19,4 +22,29 @@ public static function messageDecode(string $message)

}

public static function checkConnection(Publisher $publisher): void
{

do {

try {

$publisher->offer('ping');

$do = false;

} catch (Exception) {

$do = true;

echo '[' . date('Y-m-d H:i:s') . '] Try to connect Aeron' . PHP_EOL;

sleep(1);

}

} while ($do);

}

}

0 comments on commit 2c879e9

Please sign in to comment.