-
-
Notifications
You must be signed in to change notification settings - Fork 539
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
[5.x] Improve handling of scheduled entries #10966
Conversation
Looking good Jason. Is this something that could extend to the cache invalidators to help (and potentially make the addon no longer required)? Or is that outside of the scope at this stage? |
Love this.
Seeing as its not actioning anything, just firing the event, maybe
If that happens it could just fire the same event, seeing as its not actioning anything. |
It's on my list 👍 |
This is ready to try out if anyone wants to give it a whirl. Simply running the scheduler should be enough with |
Works a treat. Curious for the logic as to why it checks the previous minute, and not the current minute? Is it because technically the current minute, if using seconds, might still be in the future? I think avoiding words like "expired" for the event is good too - it could sometimes be about scheduling new content, or old content, so it isn't always an "expire" which sounds like it covers only one of those. My only thought would be if But otherwise, working as expected, including refreshing static caches. |
Thanks for testing!
Yes, exactly. If the entry has a datetime of In your addon a comment mentions that Statamic doesn't use seconds for publishing. I didn't understand this. It absolutely can.
Maybe I'm misunderstanding what you're saying here. I was just saying if in the future we add a feature where you can "expire" entries, we'd have the same problem and would need to use this scheduled task to detect when entries expire. (With a separate query + event)
|
Feels like Christmas every day with you guys. So basically you just turn on the default Laravel cron every minute and all is great? That is wonderful! |
Yep, in Forge or whatever hosting environment you need that single cron job that runs Locally, you can run |
That is awesome!
Just read up on that. Thanks Jason! |
This also means I can probably get rid of those (commented) scheduled commands here: https://github.com/studio1902/statamic-peak/blob/main/app/Console/Kernel.php Lovely! |
This PR adds a scheduled task that runs every minute and dispatches an event for every entry due to go live during the previous minute.
The reason it checks the previous minute is so that if the scheduler runs at for example 30s into the minute, and you have an entry with date defined at 40s into that minute, when the event gets dispatched at 30s the entry would technically still be considered scheduled. By checking the previous minute we can know that all the entries would have already become published.
Heavily inspired by the Scheduled Cache Invalidator addon by @martyf. Unlike that addon, this only supports dated collections. You may want to continue using the addon if you have more complex requirements like custom date fields.
Todo:
EntryScheduleFulfilled
?EntryScheduleResolved
?EntryScheduleCompleted
? If/when we add entry expiration, a suitable name for that would beEntryExpired
. I don't want to use "Published" since we already use that for a separate concept - the opposite of a draft.