2

I'm trying to use either whenever/rufus-scheduler gems to schedule rake tasks to run in Sinatra. I can't seem it get the tasks to run.

Here is what I've been trying:

class App < Sinatra::Base
...
    configure :development do
       every 1.minute do
         p "The task is running"
       end     
    end
end

Any ideas why this isn't working? Is this the best place to call this?

christo16
  • 4,843
  • 5
  • 42
  • 53

1 Answers1

7

Check the offical Github page of rufus-scheduler here: https://github.com/jmettraux/rufus-scheduler

require 'rubygems'
require 'sinatra'
require 'rufus/scheduler'

class App < Sinatra::Base
  scheduler = Rufus::Scheduler.start_new

  scheduler.every '5s' do
      puts "task is running"
  end

end

a = App.new

This puts the string on the console in every 5 seconds. You can replace that with your own code.

draxxxeus
  • 1,503
  • 1
  • 11
  • 14