Skip to content

Instantly share code, notes, and snippets.

@jamilbk
Created May 3, 2012 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamilbk/2584148 to your computer and use it in GitHub Desktop.
Save jamilbk/2584148 to your computer and use it in GitHub Desktop.
example showing possible Rufus production env quirks
# Example of how I'm using Rufus. I'm basically starting a scheduler, then
# using my backend to persist the job_id for the option to cancel it later.
# config/initializers/schedule.rb
SCHEDULER = Rufus::Scheduler.start_new
# app/controllers/scrapers_controller.rb
class ScrapersController < ApplicationController
def start
scraper = Scraper.find(params[:id])
job = SCHEDULER.every '1s' do
Resque.enqueue(Worker, data.next) # You get the point
end
# This is needed only in my production environment...
SCHEDULER.start
scraper.job_id = job.job_id
scraper.save
end
def stop
scraper = Scraper.find(params[:id])
# Interestingly, this doesn't work in production either...
SCHEDULER.unschedule(scraper.job_id)
scraper.job_id = nil
scraper.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment