I have to send notification to nearest user and wait for 5 min for their response, in case of no response u have to send it to all users. I used thread.spleep(5.min) but it pause my whole program. I read about background task but they will run after every 5 min but i have to run one part of fuction and then wait for 5 min while other work continues and then run remaining part again.
Whatever you want to execute after five minutes, put it in a background task.
If you use delayed_job, you can use run_at
function. It will execute one time only (not every 5 mins).
Example:
Notifier.delay(run_at: 5.minutes.from_now).signup(@user)