سؤال

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?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top