Compare commits

..

7 Commits

Author SHA1 Message Date
2b88479cec Merge pull request 'fix' (#10) from queues into dev
Reviewed-on: #10
2024-11-22 01:52:48 +03:00
7238d725dd Merge pull request 'fix' (#9) from queues into dev
Reviewed-on: #9
2024-11-22 01:48:32 +03:00
4a3fa3c2ab Merge pull request 'fix' (#8) from queues into dev
Reviewed-on: #8
2024-11-17 23:08:08 +03:00
45e1c0fe8a Merge pull request 'fix' (#7) from queues into dev
Reviewed-on: #7
2024-11-17 23:03:48 +03:00
989f7026ad Merge pull request 'fix' (#6) from queues into dev
Reviewed-on: #6
2024-11-17 22:58:40 +03:00
90378be7c5 Merge pull request 'queues' (#5) from queues into dev
Reviewed-on: #5
2024-11-17 22:56:27 +03:00
95e4f5e8da Merge pull request 'deploy' (#2) from master into dev
Reviewed-on: #2
2024-10-11 07:05:29 +03:00
6 changed files with 24 additions and 29 deletions

View File

@@ -9,7 +9,7 @@ services:
STAGE: "development" STAGE: "development"
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
networks: networks:
- queues-development - queues
command: poll command: poll
deploy: deploy:
mode: replicated mode: replicated
@@ -27,8 +27,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-development - queues
- configurator
command: worker command: worker
deploy: deploy:
mode: replicated mode: replicated
@@ -44,7 +43,7 @@ services:
STAGE: "development" STAGE: "development"
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
networks: networks:
- queues-development - queues
command: mailbox command: mailbox
deploy: deploy:
mode: replicated mode: replicated
@@ -62,7 +61,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-development - queues
command: fetch command: fetch
deploy: deploy:
mode: replicated mode: replicated
@@ -80,7 +79,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-development - queues
command: notify command: notify
deploy: deploy:
mode: replicated mode: replicated
@@ -100,7 +99,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-development - queues
command: api command: api
deploy: deploy:
mode: replicated mode: replicated
@@ -111,9 +110,7 @@ services:
order: start-first order: start-first
networks: networks:
common-infra-nginx-development: common-infra-nginx:
external: true external: true
queues-development: queues:
external: true
configurator:
external: true external: true

View File

@@ -28,7 +28,6 @@ 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
@@ -128,5 +127,3 @@ networks:
external: true external: true
queues: queues:
external: true external: true
configurator:
external: true

View File

@@ -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: [prod] runs-on: [dev]
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-development run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-dev.yaml ruz-bot

View File

@@ -25,7 +25,4 @@ 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
try: self.bot.send_message(**body, parse_mode='Markdown')
self.bot.send_message(**body, parse_mode='Markdown')
except Exception as exc:
print('Error', str(exc))

View File

@@ -15,8 +15,11 @@ class PlatformClient:
self.stage = stage self.stage = stage
self.configs = configs self.configs = configs
self.experiments = experiments self.experiments = experiments
self.endpoint = 'http://configurator/' self.endpoint = 'https://platform.sprinthub.ru/'
self.fetch_url = urllib.parse.urljoin(self.endpoint, '/api/v1/fetch') self.configs_url = urllib.parse.urljoin(self.endpoint, 'configs/get')
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 = {}
@@ -41,6 +44,7 @@ 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:

View File

@@ -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}).json() response = requests.get(f'{QUEUES_URL}/api/v1/take', headers={'queue': self.queue_name})
task = response.get('task') if response.status_code == 404:
if not task:
time.sleep(0.2) time.sleep(0.2)
continue continue
data = response.json()
try: try:
self.process(task['payload']) self.process(data['payload'])
except Exception as exc: except Exception as exc:
print(f'Error processing message id={task["id"]}, payload={task["payload"]}, exc={exc}') print(f'Error processing message id={data["id"]}, payload={data["payload"]}, exc={exc}')
continue continue
try: try:
resp = requests.post(f'{QUEUES_URL}/api/v1/finish', json={'id': task['id']}) resp = requests.post(f'{QUEUES_URL}/api/v1/finish', json={'id': data['id']})
if resp.status_code != 202: if resp.status_code != 202:
raise QueuesException raise QueuesException
except: except:
print(f'Failed to finish task id={task["id"]}') print(f'Failed to finish task id={data["id"]}')
@property @property
def queue_name(self): def queue_name(self):