Compare commits
7 Commits
2b88479cec
...
queues
| Author | SHA1 | Date | |
|---|---|---|---|
| 292bacc963 | |||
| e76cfc7994 | |||
| c146fc7f1e | |||
| 2425ee2988 | |||
| bc4f74e20f | |||
| 4e5d483208 | |||
| 1d00a27b15 |
@@ -9,7 +9,7 @@ services:
|
|||||||
STAGE: "development"
|
STAGE: "development"
|
||||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
|
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
|
||||||
networks:
|
networks:
|
||||||
- queues
|
- queues-development
|
||||||
command: poll
|
command: poll
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
@@ -27,7 +27,8 @@ services:
|
|||||||
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
|
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
|
||||||
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
|
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
|
||||||
networks:
|
networks:
|
||||||
- queues
|
- queues-development
|
||||||
|
- configurator
|
||||||
command: worker
|
command: worker
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
@@ -43,7 +44,7 @@ services:
|
|||||||
STAGE: "development"
|
STAGE: "development"
|
||||||
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
|
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
|
||||||
networks:
|
networks:
|
||||||
- queues
|
- queues-development
|
||||||
command: mailbox
|
command: mailbox
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
@@ -61,7 +62,7 @@ services:
|
|||||||
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
|
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
|
||||||
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
|
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
|
||||||
networks:
|
networks:
|
||||||
- queues
|
- queues-development
|
||||||
command: fetch
|
command: fetch
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
@@ -79,7 +80,7 @@ services:
|
|||||||
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
|
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
|
||||||
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
|
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
|
||||||
networks:
|
networks:
|
||||||
- queues
|
- queues-development
|
||||||
command: notify
|
command: notify
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
@@ -99,7 +100,7 @@ services:
|
|||||||
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
|
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
|
||||||
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
|
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
|
||||||
networks:
|
networks:
|
||||||
- queues
|
- queues-development
|
||||||
command: api
|
command: api
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
@@ -110,7 +111,9 @@ services:
|
|||||||
order: start-first
|
order: start-first
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
common-infra-nginx:
|
common-infra-nginx-development:
|
||||||
external: true
|
external: true
|
||||||
queues:
|
queues-development:
|
||||||
|
external: true
|
||||||
|
configurator:
|
||||||
external: true
|
external: true
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ services:
|
|||||||
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
|
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
|
||||||
networks:
|
networks:
|
||||||
- queues
|
- queues
|
||||||
|
- configurator
|
||||||
command: worker
|
command: worker
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
@@ -127,3 +128,5 @@ networks:
|
|||||||
external: true
|
external: true
|
||||||
queues:
|
queues:
|
||||||
external: true
|
external: true
|
||||||
|
configurator:
|
||||||
|
external: true
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ jobs:
|
|||||||
run: docker push mathwave/sprint-repo:ruz-bot
|
run: docker push mathwave/sprint-repo:ruz-bot
|
||||||
deploy-dev:
|
deploy-dev:
|
||||||
name: Deploy dev
|
name: Deploy dev
|
||||||
runs-on: [dev]
|
runs-on: [prod]
|
||||||
needs: push
|
needs: push
|
||||||
steps:
|
steps:
|
||||||
- name: login
|
- name: login
|
||||||
@@ -42,4 +42,4 @@ jobs:
|
|||||||
TELEGRAM_TOKEN_DEV: ${{ secrets.TELEGRAM_TOKEN_DEV }}
|
TELEGRAM_TOKEN_DEV: ${{ secrets.TELEGRAM_TOKEN_DEV }}
|
||||||
MONGO_PASSWORD_DEV: ${{ secrets.MONGO_PASSWORD_DEV }}
|
MONGO_PASSWORD_DEV: ${{ secrets.MONGO_PASSWORD_DEV }}
|
||||||
PLATFORM_SECURITY_TOKEN: ${{ secrets.PLATFORM_SECURITY_TOKEN }}
|
PLATFORM_SECURITY_TOKEN: ${{ secrets.PLATFORM_SECURITY_TOKEN }}
|
||||||
run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-dev.yaml ruz-bot
|
run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-dev.yaml ruz-bot-development
|
||||||
|
|||||||
@@ -25,4 +25,7 @@ class Daemon(base.Daemon, queues.TasksHandlerMixin):
|
|||||||
reply_markup = payload.get('reply_markup')
|
reply_markup = payload.get('reply_markup')
|
||||||
if reply_markup:
|
if reply_markup:
|
||||||
body['reply_markup'] = reply_markup
|
body['reply_markup'] = reply_markup
|
||||||
self.bot.send_message(**body, parse_mode='Markdown')
|
try:
|
||||||
|
self.bot.send_message(**body, parse_mode='Markdown')
|
||||||
|
except Exception as exc:
|
||||||
|
print('Error', str(exc))
|
||||||
|
|||||||
@@ -15,11 +15,8 @@ class PlatformClient:
|
|||||||
self.stage = stage
|
self.stage = stage
|
||||||
self.configs = configs
|
self.configs = configs
|
||||||
self.experiments = experiments
|
self.experiments = experiments
|
||||||
self.endpoint = 'https://platform.sprinthub.ru/'
|
self.endpoint = 'http://configurator/'
|
||||||
self.configs_url = urllib.parse.urljoin(self.endpoint, 'configs/get')
|
self.fetch_url = urllib.parse.urljoin(self.endpoint, '/api/v1/fetch')
|
||||||
self.experiments_url = urllib.parse.urljoin(self.endpoint, 'experiments/get')
|
|
||||||
self.staff_url = urllib.parse.urljoin(self.endpoint, 'is_staff')
|
|
||||||
self.fetch_url = urllib.parse.urljoin(self.endpoint, 'fetch')
|
|
||||||
self.config_storage = {}
|
self.config_storage = {}
|
||||||
self.experiment_storage = {}
|
self.experiment_storage = {}
|
||||||
self.staff_storage = {}
|
self.staff_storage = {}
|
||||||
@@ -44,7 +41,6 @@ class PlatformClient:
|
|||||||
try:
|
try:
|
||||||
response = get(
|
response = get(
|
||||||
url,
|
url,
|
||||||
headers={'X-Security-Token': self.platform_security_token},
|
|
||||||
params=params
|
params=params
|
||||||
)
|
)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
|
|||||||
@@ -17,22 +17,22 @@ class QueuesException(Exception):
|
|||||||
class TasksHandlerMixin:
|
class TasksHandlerMixin:
|
||||||
def poll(self):
|
def poll(self):
|
||||||
while True:
|
while True:
|
||||||
response = requests.get(f'{QUEUES_URL}/api/v1/take', headers={'queue': self.queue_name})
|
response = requests.get(f'{QUEUES_URL}/api/v1/take', headers={'queue': self.queue_name}).json()
|
||||||
if response.status_code == 404:
|
task = response.get('task')
|
||||||
|
if not task:
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
continue
|
continue
|
||||||
data = response.json()
|
|
||||||
try:
|
try:
|
||||||
self.process(data['payload'])
|
self.process(task['payload'])
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
print(f'Error processing message id={data["id"]}, payload={data["payload"]}, exc={exc}')
|
print(f'Error processing message id={task["id"]}, payload={task["payload"]}, exc={exc}')
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
resp = requests.post(f'{QUEUES_URL}/api/v1/finish', json={'id': data['id']})
|
resp = requests.post(f'{QUEUES_URL}/api/v1/finish', json={'id': task['id']})
|
||||||
if resp.status_code != 202:
|
if resp.status_code != 202:
|
||||||
raise QueuesException
|
raise QueuesException
|
||||||
except:
|
except:
|
||||||
print(f'Failed to finish task id={data["id"]}')
|
print(f'Failed to finish task id={task["id"]}')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def queue_name(self):
|
def queue_name(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user