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