ie8888
ie8888

Reputation: 181

resque-scheduler without rails

I am trying run the following code:

# Resque tasks
require 'resque/tasks'
require 'resque_scheduler/tasks'
namespace :resque do
 task :setup do
  require 'resque'
  require 'resque_scheduler'
  require 'resque/scheduler'

   # you probably already have this somewhere
   Resque.redis = 'localhost:6379'

   Resque.schedule = {}

   require_relative 'app'
 end
end

And app.rb

require 'resque'
require 'resque_scheduler'
require 'resque/scheduler'

Resque.enqueue_in(5.days, SendFollowUpEmail, 'id')

But I am getting undefined method `days' for 5:Fixnum

I cannot find an example without rails, any idea?

Upvotes: 2

Views: 347

Answers (1)

Didier Spezia
Didier Spezia

Reputation: 73206

Timestamp calculation syntax is provided by one of the active_support packages.

If you don't want this dependency, the first parameter of enqueue_in is a number of seconds you can manually calculate. For instance:

MINUTES=60
HOURS=60*MINUTES
DAYS=24*HOURS

Resque.enqueue_in(5*DAYS, SendFollowUpEmail, 'id')

If you still want to use the fancy timestamp calculation syntax, then you need to install active_support. You can still do it without having to install Rails:

$ gem install active_support
$ irb
irb(main):001:0> require 'active_support/time'
=> true
irb(main):002:0> print 5.days
432000=> nil

Example done with ruby 2-0-0.

Upvotes: 1

Related Questions