I just want to know how the delay job gem works. I am confused how it
detects when the server is having less load and does computing intensive
job at that time.
It doesn’t. You run separate delayed job workers that try to process the queue of delayed jobs as fast as they can. Delayed job isn’t about waiting for a less busy time - it’s mostly about decoupling the job result from the http response.
Or it just tries to do some thing, if it fails, waits for random time
and does it again?
If a job does fail it does exponential backoff, upto a configurable limit (a default of 25 attempts I think)