- ./docker/nginx_media/conf:/etc/nginx
environment:
TZ: Europe/Moscow
+ rabbitmq-yii_erp24:
+ image: rabbitmq:3-management
+ restart: always
+ ports:
+ - "5672:5672" # Порт для AMQP-протокола
+ - "15672:15672" # Порт для панели управления RabbitMQ
+ environment:
+ RABBITMQ_DEFAULT_USER: admin # Логин для доступа
+ RABBITMQ_DEFAULT_PASS: admin # Пароль для доступа
+ TZ: Europe/Moscow
+ volumes:
+ - rabbitmq_data:/var/lib/rabbitmq # Сохранение данных RabbitMQ
php-yii_erp24:
build: ./docker/php
restart: always
TZ: Europe/Moscow
command: npm run dev
- rabbitmq-yii_erp24:
- image: rabbitmq:3-management
- restart: always
- ports:
- - "5672:5672" # Порт для AMQP-протокола
- - "15672:15672" # Порт для панели управления RabbitMQ
- environment:
- RABBITMQ_DEFAULT_USER: admin # Логин для доступа
- RABBITMQ_DEFAULT_PASS: admin # Пароль для доступа
- TZ: Europe/Moscow
- volumes:
- - rabbitmq_data:/var/lib/rabbitmq # Сохранение данных RabbitMQ
volumes:
mysqldata:
autoconf dpkg-dev dpkg file g++ gcc libc-dev make pkgconf re2c postgresql-dev
RUN docker-php-ext-install pdo_pgsql
+RUN docker-php-ext-install bcmath sockets
+RUN docker-php-ext-enable bcmath sockets
+
+
#add composer
RUN wget https://getcomposer.org/installer \
&& php installer \
&& mv composer.phar /usr/local/bin/composer \
&& rm installer
-#add xdebug
-RUN apk add --no-cache $PHPIZE_DEPS \
+# Установка зависимостей для компиляции и Xdebug
+RUN apk add --no-cache --update --virtual .build-deps \
+ $PHPIZE_DEPS \
+ autoconf \
+ dpkg-dev \
+ dpkg \
+ file \
+ g++ \
+ gcc \
+ libc-dev \
+ make \
+ pkgconf \
+ re2c \
+ postgresql-dev \
&& pecl install xdebug-3.1.6 \
&& docker-php-ext-enable xdebug \
- && apk del $PHPIZE_DEPS
+ && apk del .build-deps
+
+# Установка Supervisor
+#RUN apk add --no-cache supervisor
+
+# Создаем каталог для логов Supervisor
+#RUN mkdir -p /var/log/supervisor
+
+# Копирование скрипта ожидания RabbitMQ
+#COPY /conf/wait-for-rabbitmq.sh /usr/local/bin/wait-for-rabbitmq
+#RUN chmod +x /usr/local/bin/wait-for-rabbitmq
+
+# Копирование конфигурации Supervisor
+#COPY /conf/supervisord.conf /etc/supervisor/supervisord.conf
+#COPY /conf/supervisor-conf.d/ /etc/supervisor/conf.d/
+
+
+# Set working directory
WORKDIR /www
+
+# Установка CMD для запуска Supervisor через скрипт ожидания
+#CMD ["/usr/local/bin/wait-for-rabbitmq", "supervisord", "-c", "/etc/supervisor/supervisord.conf"]
+#CMD ["/usr/local/bin/wait-for-rabbitmq", "php", "/www/yii", "queue/listen"]
\ No newline at end of file
--- /dev/null
+[program:yii-queue]
+command=php /www/yii queue/listen
+directory=/www
+autostart=true
+autorestart=true
+stderr_logfile=/var/log/supervisor/yii-queue.err.log
+stdout_logfile=/var/log/supervisor/yii-queue.out.log
+numprocs=1
+user=www-data
+stopasgroup=true
+killasgroup=true
\ No newline at end of file
--- /dev/null
+[supervisord]
+nodaemon=true
+logfile=/var/log/supervisor/supervisord.log
+logfile_maxbytes=50MB
+logfile_backups=10
+loglevel=info
+pidfile=/var/run/supervisord.pid
+childlogdir=/var/log/supervisor
+
+[include]
+files = /etc/supervisor/conf.d/*.conf
\ No newline at end of file
--- /dev/null
+#!/bin/bash
+echo "Waiting for RabbitMQ to start..."
+until nc -z rabbitmq-yii_erp24 5672; do
+ echo "RabbitMQ is unavailable - sleeping"
+ sleep 2
+done
+
+echo "RabbitMQ is up - executing command"
+exec "$@"
\ No newline at end of file
'queue' => [
'class' => Queue::class,
'dsn' => 'amqp://admin:admin@rabbitmq-yii_erp24:5672',
- 'queueName' => 'queue-name',
+ 'queueName' => 'telegram-queue',
'as log' => \yii\queue\LogBehavior::class,
-
+ 'ttr' => 300, // Время для выполнения задания
+ 'attempts' => 3, // Количество попыток
],
'cache' => [
'class' => 'yii\caching\FileCache',
'queue' => [
'class' => Queue::class,
'dsn' => 'amqp://admin:admin@rabbitmq-yii_erp24:5672',
- 'queueName' => 'queue-name',
+ 'queueName' => 'telegram-queue',
'as log' => \yii\queue\LogBehavior::class,
+ 'ttr' => 300, // Время для выполнения задания
+ 'attempts' => 3, // Количество попыток
],
'cache' => [
// Массив с ID чатов (в будущем можно заменить на запрос из базы данных)
$chatIds = [
- '730432579', // Chat ID 1
- '6207259989', // Chat ID 2
+ '730432579',
+ '6207259989',
+ '337084327',
+ '923226593',
+ '5489795686',
];
if ($request->isPost) {
namespace app\jobs;
+use yii\queue\JobInterface;
use yii_app\services\TelegramService;
-class SendTelegramMessageJob extends \yii\base\BaseObject implements \yii\queue\JobInterface
+class SendTelegramMessageJob extends \yii\base\BaseObject implements JobInterface
{
public $chatId;
public $message;
+ public static $messagesSent = 0;
+ public static $lastResetTime;
+
public function execute($queue)
{
- $telegramService = new TelegramService();
- $telegramService->sendMessageToTelegramClient($this->chatId, $this->message);
+ if (!self::$lastResetTime || (microtime(true) - self::$lastResetTime) > 1) {
+ self::$lastResetTime = microtime(true);
+ self::$messagesSent = 0;
+ }
+
+ if (self::$messagesSent >= 30) {
+ $delay = 1 - (microtime(true) - self::$lastResetTime);
+ if ($delay > 0) {
+ usleep($delay * 1e6); // Спим оставшееся время
+ }
+ self::$lastResetTime = microtime(true);
+ self::$messagesSent = 0;
+ }
+
+ TelegramService::sendMessageToTelegramClient($this->chatId, $this->message);
+
+ self::$messagesSent++;
}
-}
\ No newline at end of file
+}
$this->title = 'Отправить сообщение в Telegram';
?>
-<div class="send-message-form">
+<div class="send-message-form p-4">
<h1><?= Html::encode($this->title) ?></h1>
<?php if (Yii::$app->session->hasFlash('success')): ?>