I am making a rest-api recieves a list of instructions that a specific thread on the server should execute under a 24h period, call it a daily schedule. The same instruction is executed during a time interval:
[
{
instructionName: string
args : [
string
...
]
startHh : int
startMm : int
endHh : int
endMm : int
}
...
]
The content of args
varies depending on instructionName
.
The schedule should be persisted in MySql. Every x second the thread should asks the db for the current instruction and do some work.
My issue is that I am not sure what is the best option for storing the list of instructions in the database. As I see it I have two options:
Using the first approach, all I have to do is concat args
to a single string and then parse the json to a DTO object directly and persist it, I have to be careful not to store instructionNames and args that the working thread later can't interpret. The worker thread can easily query the instruction table and get the current instruction with regards to the time interval.
In the second approach I have to first figure out the table using instructionName, see if the args are valid for that table and then insert it. The worker thread has no way of getting the current instruction in an simple way because the instructions are separated in different tables. When the worker thread figures out what table to query the thread can be sure that the args are properly formated since they are split into individual columns.
In my application there are going to be many types of instructions and new instruction types will be added continiousely during the lifetime of the application.
It seems that both approaches has big problems, i can't figure out the best approach for my particular use case. I am wondering if i even should use a relational data base at all for these types of data.
Any input is appreciated.