Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Resque Intro

Resque Intro

Done @ Apero Ruby Lille

Robin Komiwes

October 31, 2012
Tweet

More Decks by Robin Komiwes

Other Decks in Programming

Transcript

  1. Background jobs JSON pending jobs in Redis Ruby multiples Queues

    Persistents Workers Classes that respond to `perform`
  2. # lib/resque/archive.rb class Archive @queue = :file_serve def self.perform(repo_id, branch

    = 'master') repo = Repository.find(repo_id) repo.create_archive(branch) end end # app/models/repository.rb class Repository def async_create_archive(branch) Resque.enqueue(Archive, self.id, branch) end end
  3. Steve Klabnik "Yet Another GitHub Project They've Open Sourced and

    Then Abandoned." But Resque is super awesome [...] http://blog.steveklabnik.com/posts/2012-09-22-resque--let-s-do-this
  4. daily_digest: cron: "0 */24 * * *" class: Digest description:

    "The one time a day activity digest" args: [1] bidaily_digest: cron: "0 */12 * * *" class: Digest description: "The two time a day activity digest" args: [2] instant_digest: cron: "*/5 * * * *" class: Digest description: "Send each 5 minuts a digest" args: [3]
  5. module UploadImageToCdn extend Resque::Plugins::ExponentialBackoff @queue = :cdn_upload @backoff_strategy = [0,

    0, 0, 0.5, 1, 2, 5, 10] def perform( image_id ) # ... end extend self end
  6. require 'resque/plugins/lock' module SummarizeProject extend Resque::Plugins::Lock @queue = :summarize_project def

    perform( gallery_id ) gallery = Gallery.find( gallery_id ) gallery.summarize end extend self end
  7. Run | production ★ Configure Upstart to auto-restart workers when

    they are down. ★ Capistrano deploy hook to shutdown running workers. after "deploy:create_symlink", "deploy:stop_resque"