rufus-scheduler

Can I schedule controller methods in rails using rufus-scheduler?

≯℡__Kan透↙ 提交于 2019-12-08 02:37:39
问题 Could I schedule the index method from the controller posted below? If so, how would I go about doing that? class WelcomeController < ApplicationController def index if Number.find(1) @number = Number.first @number.value += 1 @number.save else @number = Number.new @number.value = 0 end end end 回答1: So you seem to have a Number model. The first step would be to move your logic from the controller to the model: class Number def self.increment n = nil if Number.find(1) n = Number.first n.value +

Rufus Scheduler :first_in option unknown with cron

谁都会走 提交于 2019-12-06 13:31:28
I am trying to use the Rufus Scheduler (within Dashing) to schedule a cron job, but also have it run once upon the server spinning up. I am following the readme here where it is saying to do the following: scheduler.cron '00 14 * * *', :first_in => '3d' do # ... every day at 14h00, but start after 3 * 24 hours end When I try to do this, I get the following error in my job: `cron': unknown option: :first_in (ArgumentError) Has anyone come across this? Dashing is using rufus-scheduler 2.0.24 ( https://github.com/Shopify/dashing/blob/55f90939eae4d6eb64822fd3590f694418396510/dashing.gemspec#L24 )

Where should I put background processes in rails?

泄露秘密 提交于 2019-12-06 13:29:09
I'm building a Rails project that has a cron-type job that I'm managing with Rufus Scheduler. I have two questions about how to set this up appropriately in Rails: Where's the best place to put the job's code? Where should I place the Rufus code to schedule the job? How should I kick it off? To control the scheduler I would create a config/initializers/task_scheduler.rb : task_scheduler = Rufus::Scheduler.start_new task_scheduler.every("1m") do Something.to_do! # Do something every minute! end Now for the Something.to_do code, that sort of depends on what it does. Perhaps it is a data model

Rufus Scheduler not running

…衆ロ難τιáo~ 提交于 2019-12-06 12:35:49
问题 I want to do something simple with the gem rufus-scheduler: https://github.com/jmettraux/rufus-scheduler but, i can't get it to work. I have a regular rails app. I created a .rb file: # test_rufus_scheduler.rb require 'rubygems' require 'rufus/scheduler' scheduler = Rufus::Scheduler.start_new scheduler.in '1s' do puts "hello world" end Then, when I try ruby test_rufus_scheduler.rb, nothing happens. Am i doing it right? gem list shows rufus-scheduler. Thanks. 回答1: If your script exits right

Can I schedule controller methods in rails using rufus-scheduler?

拈花ヽ惹草 提交于 2019-12-06 12:27:54
Could I schedule the index method from the controller posted below? If so, how would I go about doing that? class WelcomeController < ApplicationController def index if Number.find(1) @number = Number.first @number.value += 1 @number.save else @number = Number.new @number.value = 0 end end end So you seem to have a Number model. The first step would be to move your logic from the controller to the model: class Number def self.increment n = nil if Number.find(1) n = Number.first n.value += 1 n.save else n = Number.new n.value = 0 end n end end Your controller then becomes class

Rufus scheduler not logging in production

坚强是说给别人听的谎言 提交于 2019-12-06 04:41:32
My rails app kicks off a process with rufus-scheduler in an initializer. Here's a stripped-down version of the initializer's code: # config.logger isn't available here, so we have to grab it from the Rails object logger = RAILS_DEFAULT_LOGGER logger.warn(Time.now.to_s + ": Starting Rufus Scheduler") # run every Wednesday at 10 AM cron_string = '0 10 * * 3' scheduler = Rufus::Scheduler.start_new scheduler.cron cron_string do logger.warn(Time.now.to_s + ": Starting Background Process") (do work here) logger.warn(Time.now.to_s + ": Finished Background Process") end logger.warn(Time.now.to_s + ":

Best way to not run rufus-scheduler when starting a rails console

血红的双手。 提交于 2019-12-05 07:26:54
I use rufus-scheduler to run some periodic tasks, but they are extremely annoying to have in the rails console when I just want to test things. Is there an easy way to stop all rufus-scheduler tasks when starting a console automatically? In the code that starts the scheduler if i can check that i am just in a rails console I can not run them, or if there is a way to run some callbacks when the console starts I can also shut them down there. Thanks Brian Glick Based on Rails check if IRB console or webpage : unless self.private_methods.include? 'irb_binding' #put your rufus scheduling here end

Rufus scheduler running multiple times with unicorn, fixed with :lockfile, but how to eliminate the error msg?

 ̄綄美尐妖づ 提交于 2019-12-05 02:26:09
scheduler = Rufus::Scheduler.new :lockfile => ".rufus-scheduler.lock" scheduler.every("60") do ... end Environment: Ubuntu, rails 4, rufus, unicorn, nginx Unicorn has multiple workers, so the above 'every' task will be executed multiple times every 60 seconds. According to the answer for this one: rufus scheduler running twice each time , I added :lockfile option, and it works! However, from the log, it seems that the 'every' task still tries to be called, resulting in a lot of error messages: E, [2014-05-09T01:59:47.496840 #2747] ERROR -- : cannot schedule, scheduler is down or shutting down

Rufus Scheduler not running

拈花ヽ惹草 提交于 2019-12-04 18:23:50
I want to do something simple with the gem rufus-scheduler: https://github.com/jmettraux/rufus-scheduler but, i can't get it to work. I have a regular rails app. I created a .rb file: # test_rufus_scheduler.rb require 'rubygems' require 'rufus/scheduler' scheduler = Rufus::Scheduler.start_new scheduler.in '1s' do puts "hello world" end Then, when I try ruby test_rufus_scheduler.rb, nothing happens. Am i doing it right? gem list shows rufus-scheduler. Thanks. If your script exits right away please try to add scheduler.join at the end. Please note that it's different when running the script

How to get rufus-scheduler working with a Rails app deployed to Heroku?

ぃ、小莉子 提交于 2019-12-04 13:35:16
问题 In ./config/initializers I've created a file called task_scheduler.rb and it contains the following code: require 'rufus-scheduler' require 'mechanize' scheduler = Rufus::Scheduler.new scheduler.every("1h") do puts "Starting Rufus Scheduler - Task 1 - Checking exampleShop for new orders" a = Mechanize.new a.get('http://exampleshop.nl/admin/') do |page| # Select the login form login_form = page.forms.first # Insert the username and password login_form.username = 'username' login_form.password