A Quick Tip for Delayed Job in Rails

I've been pondering on this delayed job in the Rails app. User specify a time that they'd like the job to run. Passing that into the delayed job is straight forward.

CustomerEmail.delayed_job(queue: 'mail', run_at: params[:date])

But when I checked on the run_at column in delayed_jobs, I got this:

 id  |           run_at           |         updated_at         
-----+----------------------------+----------------------------
 835 | 2016-08-19 16:27:07.003945 | 2016-08-19 16:27:07.004107
 834 | 2016-08-19 16:27:02.516581 | 2016-08-19 16:27:02.517648
 833 | 2016-08-19 16:25:06.81385  | 2016-08-19 16:25:06.814095
 832 | 2016-08-19 16:19:20.601837 | 2016-08-19 16:19:20.602038

It seems like run_at column was updated the same time as updated_at, regardless what date has been called on delayed_job.

In further investigation, I found if I ran

CustomerEmail.delayed_job(queue: 'mail', run_at: 1.day.from.now)

I got

 id |           run_at           |         updated_at         
----+----------------------------+----------------------------
 852| 2016-08-20 16:49:16        | 2016-08-19 16:49:16

The culprit is that run_at has to take a date object. If a string passed in, it ignores the string and set current update time.