oldmoe / litestack

MIT License
1.02k stars 56 forks source link

Expected `SomeJob.perform_in(5.seconds)` to execute in 5 seconds #104

Closed francois closed 4 months ago

francois commented 5 months ago

This would be a nice convenience, when Litejob is used in the context of a Rails application. Maybe the adaptation needs to live in a Railtie or elsewhere?

class PretenderJob < ApplicationJob
  queue_as :default

  def perform(*args)
    Rails.logger.info "Pretender starting... #{args.inspect}"
    sleep 5
    Rails.logger.info "Pretender stopping #{args.inspect}"
  end
end
irb(main):002> PretenderJob.perform_in(10.seconds, '10 seconds')
/Users/francois/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/sqlite3-1.7.3-x86_64-darwin/lib/sqlite3/statement.rb:41:in `bind_param': can't prepare ActiveSupport::Duration (RuntimeError)

The easiest way to achieve this involves using .perform_at and using Time#from_now:

irb(main):001> PretenderJob.perform_at(10.seconds.from_now, '10 seconds')
=> ["6CF98D8D19A5769F4045DC580ABE4F837F996C214E5E5E816DD28525D9BB818A", "default"]
$ bundle show | ag '\brails\b|litestack|sqlite3\b'
  * litestack (0.4.3)
  * rails (7.1.3.2)
  * sqlite3 (1.7.3)
oldmoe commented 4 months ago

Hi Francois, I might be missing something, but how are you using the Litejob interface (perfrom_in, etc) when you are inheriting from ApplicationJob?