Question

I want to create a feature on my website that allows users to schedule a post at a specific time. The posts will be placed in a queue and then posted at the specified time. What is the proper method for handling this? Do I need to create a separate cron job for each individual scheduled post?

Was it helpful?

Solution

Typically this is done with a single cron job acting as "trigger". That trigger (a php script) checks the list of pending jobs in the database and executes one or more.

It might spawn sub requests for each job to improve robustness, but this adds load to the system.

It is important to mark started jobs inside the database so that in case of concurrent trigger processes (whyever, for example system load), a single job is not started twice. This is especially true for jobs that crash...

You might also want to implementing a locking strategy, so that only one single concurrent trigger request is possible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top