I have tasks which need to be repeatedly executed in specified hours and days. For example, task A should be executed at 1, 2 and 3 p.m. on Monday and at 2, 8, 11 p.m. on Friday. Task B should be executed at 4 a.m. on Monday and so on. Basically every task could be executed at any hour of any day. If all tasks for current hour have been executed we execute them all again. So it's like a priority queue for every hour.
I'm using Postgres and right now it's JSONB facilities. I have table tasks
which contain task related info and schedule. Schedule for every task looks something like this:
{
"Mo": [
1,
2,
3
],
"Fr": [
4,
5,
6
]
}
But I don't like that json is not strongly typed, query which selects tasks looks really ugly and I think performance of query could be better.
I thought may be I create table where I store each hour of week and, for example, hours and table executions where I store id of tasks correlated to id of hours. Could work, but it seems very bad for storage space(amount of tasks is about 100000 right now and growing).
So I wonder how to design database properly for such case?