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
Flows cron triggers multiple times #15052
Comments
I forgot to add that it starts with a cron step |
This is a known limitation of the cron setup currently, as multiple instances of directus aren't aware of each other, so each instance of directus will execute the cron job simultaneously. I'll leave this open as a bug, as it's already a thing we're actively working on 👍🏻 |
Thank you! |
Ref #13381 which is the primary discussion on solutions for this known limitation. |
We should generate a redis key for flow ID + the timestamp the cron is supposed to run (not exact current timestamp) with a TTL of like 3 seconds. We can run a redis increment call on that key, if it returns 1, the current instance is the one to run the flow, otherwise, ignore it. |
Linear: ENG-209 |
Is there any update here? I'm running into race conditions in my app that I can't seem to get around without solving this. Thanks! |
We are also highly interested into an update of the fix. We running into the same issue on a scaled system. Thanks! |
Is there a workaround? Is it possible to isolate cron tasks to a single instance? For example,
|
We had a little discussion about the best fix for this issue and the solution we came up with is to use a "Synchronized Clock" mechanism via redis. The way this mechanism should work is as follows: The supposed next execution time of each flow with a schedule trigger is stored in redis with the UUID (and some prefix like This mechanism ensures that, provided the internal clocks of all instances do not deviate by more than one second, for each supposed execution time of a schedule flow, the flow is executed only by the instance that accesses the value in redis first. |
@rijkvanzanten the current cache (Keyv) doesn't support atomic updates correct? So are you switching it out or communicating with redis more directly. Also, I wonder if having to need redis for this to work is viable, vs just having a directus_queue table in the database like laravel has? |
Keyv just uses Redis under the hood. Redis is single-threaded, so every update is atomic by default 🙂
Writes to a database aren't reliably atomic or timing-error-free like Redis would be for this use case, so I'm hesitant to go that route. Besides, we're already requiring Redis when you're in a horizontally scaling environment as we're relying on it's pubsub for websockets among other things 👍🏻 |
👍 for redis. Using relational tables will eventually result in table bloat, especially under heavy use, which will need to be monitored and managed; even so, tables may need to be rotated occasionally. |
Describe the Bug
Flows Trigger 3 times no matter what.
Created New Flow to validate:
Only the Create Data functionality causes it.
Emits Events On and Off Does Not Affect it
To Reproduce
You will get 3 emails and items
Errors Shown
No response
What version of Directus are you using?
9.15.1
What version of Node.js are you using?
16.16.0
What database are you using?
cloud pg
What browser are you using?
chrome
How are you deploying Directus?
cloud
The text was updated successfully, but these errors were encountered: