Also, I noticed that there is a race condition: If at the moment we pause a job, a message comes which makes it crashed or done: The message will be queued on the socket, we update the database with paused state, then we send the command to the worker which does nothing since the job has crashed. However, after that, the server processes the Done/Crashed message and tries to change the job status from PAUSED to DONE/CANCELLED, which up to now would have crashed the server.
As a result, I we should allow this kind of transition.
Instead of print() we should use logging.
Also, I noticed that there is a race condition: If at the moment we pause a job, a message comes which makes it crashed or done: The message will be queued on the socket, we update the database with paused state, then we send the command to the worker which does nothing since the job has crashed. However, after that, the server processes the Done/Crashed message and tries to change the job status from PAUSED to DONE/CANCELLED, which up to now would have crashed the server.
As a result, I we should allow this kind of transition.