· 1 min read
Screencast: Resque
Downloads in verschiedenen Formaten:
Resourcen:
bash
[bash] brew install redis redis-server /usr/local/etc/redis.conf resque-web rake resque:work QUEUE=’*’ [/bash]
Gemfile
[ruby] gem ‘resque’, :require => “resque/server” [/ruby]
lib/tasks/resque.rake
[ruby] Resque::Server.use(Rack::Auth::Basic) do |user, password| password == “secret” end [/ruby]
snippets_controller.rb
[ruby] Resque.enqueue(SnippetHighlighter, @snippet.id) [/ruby]
app/workers/snippet_highlighter.rb
[ruby] class SnippetHighlighter @queue = :snippets_queue def self.perform(snippet_id) snippet = Snippet.find(snippet_id) uri = URI.parse(‘http://pygments.appspot.com/’) request = Net::HTTP.post_form(uri, {‘lang’ => snippet.language, ‘code’ => snippet.plain_code}) snippet.update_attribute(:highlighted_code, request.body) end end [/ruby]
config/routes.rb
[ruby] mount Resque::Server, :at => “/resque” [/ruby]
config/initializers/resque_auth.rb
[ruby] Resque::Server.use(Rack::Auth::Basic) do |user, password| password == “secret” end [/ruby]