-
-
Notifications
You must be signed in to change notification settings - Fork 645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace RMQ with Tasks #104
Comments
@heavysaturn (mentioning as this is a migrated ticket) I'm unable to see the related issue ticket for this, but this should be super simple to implement, as we don't need to make any special event dispatcher for this; we can just take advantage of For example task retrieval could be something like this (abstracting out the actual api fetching code): tasks = await self.retrive_new_tasks() # gets the tasks from the api endpoint
for task in tasks:
# example of data would be:
# task["task_id"] = "b8b97d2f-13b7-4061-ad38-5245a2d02cda"
# task["type"] = "add_role"
# task["target_id"] = value of 174764205927432192
# task["role_id"] = value of 423054537079783434
# task["reason"] = value of "Code Jam approval"
task_id= task.pop("task_id")
task_type = task.pop("type")
task_event = f"task_{task_type}"
self.bot.dispatch(task_event, **task)
# tell api it's dispatched to distinguish tasks already actioned
await self.mark_task_dispatched(task_id) and then elsewhere that wants to action that task event: async def on_task_add_role(self, target_id, role_id, reason):
member = self.guild.get_member(target_id)
if not member:
log.info(f"Task 'Add Role' unable to be completed: Member not found ({target_id})
return
role = self.guild.get_role(role_id)
if not role:
log.info(f"Task 'Add Role' unable to be completed: Role not found ({target_id})
return
await member.add_roles(role, reason=reason) As long as this coroutine for the task event is present in a cog, it'll be detected as a valid event as it starts with Just as a note: PR #289 removes all RMQ totally, effectively actioning this issue, but does not add in support for non-message events the site may want to send (as the site instead is using discord webhooks to send notifications to discord channels). So the above only really applies to all non-messaging events such as role changes. |
ohhh, that's a very interesting way to implement this. this isn't a super urgent need, but we'll need it for automating code jam setups. I think I am 100% on board with this approach. also, I did not know that was a thing. |
RMQ is gone already. Where would we need to make use such task system at this point? |
The idea was to use it for Code Jam stuff, but frankly this ticket feels really stale and I think it's better we close it and rethink the Code Jam stuff when that time comes. |
Originally posted by Leon Sandøy:
We should remove the RMQ integration, and replace it instead with Tasks, as described in https://gitlab.com/python-discord/projects/site/issues/45. The RMQ code is an unholy mess that nobody likes working with, and a simple one-way-communication system is far simpler for contribs and core devs alike to wrap their heads around. It also wouldn't really perform very differently anyway, so for our use case it should be perfect.
The Task interface should be abstracted away so that our contribs never have to worry about doing the actual polling. The bot should just do this and then trigger a sort of task event, that our contribs can write handlers for. This should be as simple as possible, and it would be ideal if it mimics how events work in discord.py already. perhaps an
on_task_received
event handler that can optionally be defined for each cog, and some sort of constant to define relationships between task types and cog? Something like that.The text was updated successfully, but these errors were encountered: