You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I feel like this has to be split into two separate topics:
support for executing something on a schedule (the actual routine), e.g. every 5 mins (also, doesnt need persistance)
add a service that is accessible to all features, allowing them to schedule one-shot tasks at a given date/time or with a delay, which is persisted in case the bot shuts down.
Regarding the second part, we decided that there is no pleasant way to offer a generic scheduler solution for persisted-one-shot-tasks.
The problem is that its pretty much impossible to persist a generic Runnable (the task to persist) in the database in a non-fragile way. One possibility was to persist something like
(with Java serialization or JSON or similar)
which at least has the benefit that it can inject a fresh JDA, while the user can choose what exactly to serialize and what not. However, it is still too fragile for practical use. For example, suppose a /remind-me what:"happy birthday" when:2 years, when this is executed in 2 years, chances are high that JDA (or another component in the code base) was updated in a way that makes the old serialized code invalid (for example, because the Discord end-point to post messages has changed).
Alternative approaches, such as simply storing the name of a static method to execute (so that only the location of the code but not the code itself is serialized), are not powerful enough and too limiting.
We concluded that users interested in a persisted-scheduled-one-shot-task features need to roll a custom domain-specific solution each.
However, we agreed that a big part of that can still be taken by a generic helper solution that assists users in creating such a custom system. It could for example register listeners by name and then persist simple content, such as the name of the interested listeners, together with the schedule. That way, it could do all the heavy lifting of the task scheduling but instead of triggering persisted tasks, it merely triggeres persisted listeners, who know better how to do the actual task at hand.
Before we create such a system however, we first want to wait for one or two users to create custom solutions. It is much easier to identify and extract the duplicated logic and put them into a helper system in hindsight.
if u do this the routines can still be stored in the db (for example a table containing a list of channels can be stored in the database and converted into a Routine that monitors those channels) (or a table of users can be converted into a routine that mutes those users on rejoin)
tl:dr storing runnables in the database is DEFINTELY a bad idea, however there is absolutely nothing wrong with storing the data thats needed to generate runnables in a custom manner
Yeah. I didnt saw a need to persist routines ("execute me every 5 minutes") yet though. Their schedule can just be restarted upon bot launch. "Bot launches; Hey routine, whats ur schedule again? Okay will execute u each 5 mins."
The persistence bit is only interesting for one-shot tasks like /remind-me and similar. In which case the part that will be persisted should likely just be the "link" to the callsite. For example with by-name-registration (similar to how we persist the command routing). Right now we have no single user for such a feature yet though, I would like to wait for /remind-me or similar to be coded before adding a helper system for them.
Activity
Moved routines and listeners inside Commands
Moved routines and listeners inside Commands
Moved routines and listeners inside Commands
Moved routines and listeners inside Commands
github-actions commentedon Dec 17, 2021
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
Zabuzard commentedon Dec 17, 2021
This is actually still relevant, we need it eventually.
github-actions commentedon Jan 17, 2022
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
Zabuzard commentedon Jan 18, 2022
I feel like this has to be split into two separate topics:
Zabuzard commentedon Jan 18, 2022
Regarding the second part, we decided that there is no pleasant way to offer a generic scheduler solution for persisted-one-shot-tasks.
The problem is that its pretty much impossible to persist a generic
Runnable(the task to persist) in the database in a non-fragile way. One possibility was to persist something like(with Java serialization or JSON or similar)
which at least has the benefit that it can inject a fresh JDA, while the user can choose what exactly to serialize and what not. However, it is still too fragile for practical use. For example, suppose a
/remind-me what:"happy birthday" when:2 years, when this is executed in 2 years, chances are high that JDA (or another component in the code base) was updated in a way that makes the old serialized code invalid (for example, because the Discord end-point to post messages has changed).Alternative approaches, such as simply storing the name of a static method to execute (so that only the location of the code but not the code itself is serialized), are not powerful enough and too limiting.
We concluded that users interested in a persisted-scheduled-one-shot-task features need to roll a custom domain-specific solution each.
However, we agreed that a big part of that can still be taken by a generic helper solution that assists users in creating such a custom system. It could for example register listeners by name and then persist simple content, such as the name of the interested listeners, together with the schedule. That way, it could do all the heavy lifting of the task scheduling but instead of triggering persisted tasks, it merely triggeres persisted listeners, who know better how to do the actual task at hand.
Before we create such a system however, we first want to wait for one or two users to create custom solutions. It is much easier to identify and extract the duplicated logic and put them into a helper system in hindsight.
borgrel commentedon Jan 19, 2022
Agreed, Runnables should NOT be persisted in the database however there is no problem with using the database to persist the routines
u dont need special serializable functionality or some stuff
if u do this the routines can still be stored in the db (for example a table containing a list of channels can be stored in the database and converted into a Routine that monitors those channels) (or a table of users can be converted into a routine that mutes those users on rejoin)
tl:dr storing runnables in the database is DEFINTELY a bad idea, however there is absolutely nothing wrong with storing the data thats needed to generate runnables in a custom manner
Zabuzard commentedon Jan 19, 2022
Yeah. I didnt saw a need to persist routines ("execute me every 5 minutes") yet though. Their schedule can just be restarted upon bot launch. "Bot launches; Hey routine, whats ur schedule again? Okay will execute u each 5 mins."
The persistence bit is only interesting for one-shot tasks like
/remind-meand similar. In which case the part that will be persisted should likely just be the "link" to the callsite. For example with by-name-registration (similar to how we persist the command routing). Right now we have no single user for such a feature yet though, I would like to wait for/remind-meor similar to be coded before adding a helper system for them.