Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Add redis stream #16

Merged
merged 33 commits into from
Sep 18, 2019
Merged

Add redis stream #16

merged 33 commits into from
Sep 18, 2019

Conversation

zteeed
Copy link
Owner

@zteeed zteeed commented Aug 11, 2019

No description provided.

@zteeed zteeed requested a review from bonnetn August 11, 2019 02:15
Copy link
Collaborator

@bonnetn bonnetn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

la v2 se rapproche :D

worker/main.py Outdated Show resolved Hide resolved
worker/main.py Outdated Show resolved Hide resolved
worker/requirements.in Outdated Show resolved Hide resolved
worker/worker/__init__.py Outdated Show resolved Hide resolved
worker/requirements.in Show resolved Hide resolved
worker/main.py Outdated Show resolved Hide resolved
worker/main.py Outdated Show resolved Hide resolved
api/api/constants.py Outdated Show resolved Hide resolved
api/api/handlers.py Outdated Show resolved Hide resolved
api/api/handlers.py Outdated Show resolved Hide resolved
api/api/handlers.py Show resolved Hide resolved
api/api/handlers.py Outdated Show resolved Hide resolved
if stream_name == REDIS_STREAM_CHALLENGES:
await set_all_challenges()

await app.redis.xack(stream_name, CG_NAME, message_id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya pas un mode autoack sur aioredis?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

euh aucune idée jvais regarder

worker/worker/__init__.py Outdated Show resolved Hide resolved
GITHUB_ACCOUNTS = ["https://github.com/zteeed", "https://github.com/bonnetn"]
REDIS_STREAM_USERS = 'update_users'
REDIS_STREAM_CHALLENGES = 'update_challenges'
CG_NAME = 'rootme'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu peux pas merge api/api/constants.py et celui là? si tu mets les mêmes valeurs..

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bah ca veut dire que les subprojects worker et api sont dépendants, a terme peut etre gérer ça avec des variables d'environnements spécifiés dans les Dockerfile ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui tu peux, ou laisse comme ça.si tu as une bonne raison c'est pas grave

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

je note ca quelque part ca sera modifié sur la partie mise en prod

worker/worker/redis_interface/challenges.py Outdated Show resolved Hide resolved
worker/worker/redis_interface/details.py Show resolved Hide resolved
api/api/handlers.py Show resolved Hide resolved
api/api/handlers.py Show resolved Hide resolved
data = await redis_app.get(f'{key}')
now = datetime.now()
timestamp = extract_timestamp_last_update(data)
timeout = get_timeout(handler_type)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi tu passes pas le timeout directement en argumetn de cette fonction? C'est la fonction parente qui a le plus de connaissance sur quel timeout mettre

api/src/fetch.py Outdated Show resolved Hide resolved
elif handler_type == 'dynamic_user' and arg is not None and condition:
await redis_app.xadd(REDIS_STREAM_USERS, {b'username': arg.encode()})
elif handler_type == 'dynamic_categories' and arg is not None and condition:
await redis_app.xadd(REDIS_STREAM_CHALLENGES, {b'update': b"ok"})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update:ok est ignoré non? pourquoi mettre une valeur ici?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peu importe oui

worker/worker/__init__.py Show resolved Hide resolved
worker/worker/redis_interface/challenges.py Outdated Show resolved Hide resolved
@@ -1,4 +1,5 @@
import itertools
from typing import List, Tuple
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ce fichier est plus utilisé si?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sisi

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ca concernera une autre PR ca

@bonnetn
Copy link
Collaborator

bonnetn commented Sep 18, 2019

Je pense qu'on peut améliorer la structure du projet:
Pour l'instant il y a deux modules:

  • redis_interface: qui représente les interactions avec le monde
  • parser: qui parse

Je trouve que le module parser est super car il est totalement self-contained. Il prend des strings et les parse en structures de données que tu veux, il fait son taff et juste sont taff..

Par contre redis_interface fait un peu tout... Genre dans worker/worker/redis_interface/challenges.py, la fonction retrieve_category_info n'a aucun rapport avec Redis, et en plus elle ne fait pas l'interface avec le système et redis mais plutôt entre le système et Rootme. Alors je sais bien que c'est une fonction qui n'est utilisée que dans ce fichier (d'ailleurs les fonctions non exportées devraient être préfixées d'un _), mais ca correspond quand même pas à ce qu'on attend intuitivement d'une "interface vers redis".

Je pense que l'actuel redis_interface peut être split en 3 modules, ça va t'aider à avoir une architecture plus claire, écrire tes tests plus facilement et potentiellement de pouvoir faire des refactoring plus facilement.
redis_interface pourrait devenir:

  • redis_interface: garder le module, mais y mettre QUE des fonctions qui font l'interface entre ton système et redis. (en gros ca serait un adapter, dans le "port and adapter pattern")
  • root_me_interface: Les fonction qui concernent l'interfacage avec rootme, en gros ca serait toujours un appel au HTTP_client + parse et on retourne la valeur. (comme ca ca se teste super simplement)
  • ??? le nom reste à définir (peut être juste worker) qui établit le workflow de ton worker. Genre par exemple, quand on a un ordre d'update, d'abord on uitilise l'interface redis pour récup le timestamp, on check si la resource doit être update, si elle doit être update, on utilise l'interface rootme pour recup les infos, puis on met des données dans redis en utilisant l'interface redis. C'est un exemple de "workflow" qui serait contenu dans ce module

C'est juste une proposition, mais avec ça, juste en lisant la 3ème classe on peut comprendre ce que fait concrètement ton worker, et en lisant les interfaces, on peut comprendre COMMENT il fait

@zteeed zteeed merged commit 77fa3cc into master Sep 18, 2019
@zteeed zteeed deleted the add_redis_stream branch September 25, 2019 03:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants