Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃殌 Feature: Schedule an execution for the future #5489

Open
2 tasks done
Silfalion opened this issue May 2, 2023 · 8 comments
Open
2 tasks done

馃殌 Feature: Schedule an execution for the future #5489

Silfalion opened this issue May 2, 2023 · 8 comments
Labels
enhancement New feature or request product / functions Fixes and upgrades for the Appwrite Functions.

Comments

@Silfalion
Copy link

馃敄 Feature description

So the objective of this issue is to suggest the introduction of a programmatically settable task scheduler for functions.

馃帳 Pitch

Right now function schedule is only set at the function creation and can only be changed in a way that overrides the previous schedule.

The suggestion would be to have a variable, as @Meldiron proposed(on Discord), for the execute method that would contain a datetime. The function would execute at that precise time.

This would allow to have for example 5 executions planed for a function with different inputs without changing the initial frequency of the function.

Another very interesting feature would also be, as Mattias Aabmets(Discord) suggested, to have yet another variable containing a cron for tasks for which the logic(function code) is known but frequency is erratic.

An example that would illustrate these 2 suggestions would be a reminder app. The first reminder that would take advantage of the first suggestion is setting up a datetime one day prior to a meeting to prep for it.

The second aspect of the example would be a reminder that rings me every few days(CRON) for my morning sport routine.

Right now I find myself needing to have a mini server that hit a function endpoint at a specific frequency/date that I set through the server's Api to emulate this feature , and I think it would be a powerful addition to appwrite if bundeled directly into it.

Looking forward to hearing your thoughts:)

馃憖 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

馃彚 Have you read the Code of Conduct?

@aabmets
Copy link

aabmets commented May 2, 2023

@Silfalion
Appwrite supports assigning CRON schedules to Cloud Functions.

First create a hourly "clock" function with CRON syntax 0 * * * *, which executes every hour at minute 0. You can also create a minute "clock" with CRON syntax * * * * *, which executes every minute. These are just few examples, you can customize the delay based on your needs using the official CRON syntax.

Next, create a DB collection of documents, where each document has two fields: executionStartTime and functionName. You can also add additional fields for function parameters if you need this complexity.

On each tick of the clock function, it will read all the documents in the collection and parse the received records. If a record contains execution time which is in the past, the clock function will call an execution of the function that the record points to (with params from the record if you implemented this) and then deletes that document from the collection, because the task has been executed. You can also implement "executeInterval", which causes the clock to update the document in the DB with the next execution time.

This sounds all a lot like duplicating CRON functionality, but this allows you to set "CRON" tasks over the internet, if you implement another function which the user is able to call to insert execution tasks into the scheduler collection.

The way I see it, it does require a bit of work to implement, but it's already possible to achieve with existing capabilities.

@Silfalion
Copy link
Author

Silfalion commented May 2, 2023

@aabmets

Thought of that at the beginning but the schedule of the task has to be very precise and execute at the specified time.

An every minute cron would be the solution right now but that feels like a lot of executions.

@aabmets
Copy link

aabmets commented May 2, 2023

@Silfalion
How do you think Appwrite is supposed to execute functions at a later time? Something has to check if the execution time has arrived and then execute the associated function at that time. The clock is inevitable, the question is whether this complexity is abstracted away from the end user by Appwrite devs.

@Silfalion
Copy link
Author

Silfalion commented May 2, 2023

That's exactly my point. A cron that checks when to execute a function is not the same as a cron that executes a function that checks if it should execute a task. There is an important overhead.

@aabmets
Copy link

aabmets commented May 2, 2023

@Silfalion
I think you have insufficient knowledge how a comparator works. The cron execution time evaluation is literally an if statement. When a function should be executed is evaluated with an if statement.

@Silfalion
Copy link
Author

Silfalion commented May 2, 2023

@aabmets

Wait... I think we're talking about the same thing in a different way. I meant that the solution you described earlier is not desirable because it is setup by the user, but it is how it would be made inside Appwrite as you pointed out, this issue is about requesting this feature to be included in Appwrite itself

Concerning the overhead, do you mean that if I create an Appwrite function with say python, to execute the solution you described, the computational load of executing the function into the runtime on every minute would be equivalent to Appwrite doing by itself?

@aabmets
Copy link

aabmets commented May 2, 2023

@Silfalion

Concerning the overhead, do you mean that if I create an Appwrite function with say python, to execute the solution you described, the computational load of executing the function into the runtime on every minute would be equivalent to Appwrite doing by itself?

Appwrite uses Resque internally to queue jobs. Resque is faster than doing it yourself in cloud functions, but the difference is insignificant. There would be a noticeable performane drop if you had to schedule millions of tasks each minute by one Appwrite container. If you scale Appwrite correctly with Docker Swarm, which you are supposed to do anyways, then this becomes a non-issue.

@Silfalion
Copy link
Author

Silfalion commented May 2, 2023

@aabmets

Hm I see, didn't know Appwrite runtimes are that efficient. Well thank you for the information and your detailed explanation earlier. I may go with that approach since it's not as slow as I thought it was

@stnguyen90 stnguyen90 added enhancement New feature or request and removed feature labels Mar 20, 2024
@stnguyen90 stnguyen90 changed the title 馃殌 Feature: programmatically settable tasks for functions 馃殌 Feature: Schedule an execution for the future May 6, 2024
@stnguyen90 stnguyen90 added the product / functions Fixes and upgrades for the Appwrite Functions. label May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request product / functions Fixes and upgrades for the Appwrite Functions.
Projects
None yet
Development

No branches or pull requests

4 participants