Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Create a Scheduler (e.g. to schedule tweets, or an api request)

I have a table of schedule items, they may be scheduled for the same time. I'm wondering how to have them all execute at the correct time when:

The problem I see is that executing one scheduled item (like a scheduled twitter post) requires an API request which may take up to a second or two - probably longer. If I execute them sequentially + there are too many scheduled items at the same time, the time they get executed at could be after the scheduled time.

How would I go about building this "scheduling" system that avoids these problems? Any tips, advice?

Thanks!

like image 895
rksprst Avatar asked Feb 27 '23 17:02

rksprst


2 Answers

I would use a Windows service to accomplish this. Then each of the items should be scheduled asynchronously using the BackgroundWorker process. This would allow all of the scheduled processes to be launched rapidly asynchronously so they don't collide and aren't depending on the previous one finishing before kicking off.

like image 142
Joel Etherton Avatar answered Apr 25 '23 18:04

Joel Etherton


You might want to consider Quartz.NET. Gives you much flexibility in terms of scheduling and task execution.

like image 43
o.k.w Avatar answered Apr 25 '23 16:04

o.k.w