Problem 1 - Locking
We have developed a job management system that integrates with various other job systems.
Within our application, there can be multiple actors accessing our jobs at any given time.
Approach - Locking
We think we can achieve an integral job model using database locking.
We are thinking of doing this by adding the following
Prisma
model Job {
...
Lock: ModelLock @relation(...)
}
model Lock {
id Int @id @default(autoincrement())
lockedBy User
lockedAt DateTime
locked Boolean
takeOverMessage? String
takeOverAt? DateTime
Job? Job @relation(...)
...
}
Logic
When there is an active lock, anyone else opening the job will be prompted that it’s locked. They can read only or kick out the other user.
It is assumed the editing user will be polling the Lock model to ensure no one is trying to kick them out.
They will then have a certain amount of time to respond to the takeover request.
Problem 2 - Drafting
Our users should be able to save the form at any point in its completion and other actors be able to access this data across devices.
Approach 2 - Drafting
Save json data under the job table
Prisma
model Job {
...
draft?: JSON
}
Logic
Save the json data under the job periodically, and on load of the form pre-fill the fields. On submit the draft is reset.
Any help is appreciated!