Say I have a database with a table, each record in this table corresponds with an action to be ececuted. This table has a datetime field in which the next moment the action should be executed is stored.
This table is being read by a windows servic and the actions are stored in a datastructure. Every few minutes the service reads the table and new actions are merged into the datastructure, so actions created in the meanwhile don't get missed out.
Each action has a certain repeat interval. When an action has run, the datetime field gets updated to the next moment it should run based on that interval.
Now here's where I'm wondering about the correct course of action: what is the preferred way to actually start the action at its given time?
Say I've an action that should be run at 09:00 in the datastructure, how do I ensure it getting triggered at 09:00? What I currently have in mind is to check the datastructure every minute, compare the current time with the time the action is scheduled and if they match, execute the action and update the execute time of the action according to its associated interval.
As a datastructure I tend to think in the line of a queue, so I can have the next job in front and I only have to check the first, but then I need to rearrange the queue everytime new actions are found.
My main point of interest is a good approach for checking if an action should be executed, an appropriate datastructure will follow. The amount of actions in the table will be really low, no more then 25. I have no control over the database so everything should be done programmatically in C# in case your're wondering. Any tips, experiences or points of advise?