Created
May 3, 2012 08:02
-
-
Save jamilbk/2584148 to your computer and use it in GitHub Desktop.
example showing possible Rufus production env quirks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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