· 1 min read
Screencast: Queue Classic
Downloads in verschiedenen Formaten:
Resourcen:
config/application.rb
[ruby] # Although not shown in the episode, it is a good idea to uncomment this line in config/application.rb # This is because the schema we are generating here cannot be represented in Ruby. config.active_record.schema_format = :sql [/ruby]
terminal
[bash] rails g migration add_queue_classic rails g migration setup_queue_classic rake db:migrate rake qc:work rails c [/bash]
rails console
[ruby] QC.enqueue “puts”, “hello world” QC.enqueue “puts”, msg: “hello world” QC.enqueue “puts”, “msg” => “hello world” [/ruby]
Gemfile
[ruby] gem ‘queue_classic’, ‘2.0.0rc12’ [/ruby]
lib/tasks/queue_classic.rake
[ruby] require “queue_classic” require “queue_classic/tasks” [/ruby]
config/initializers/queue_classic.rb
[ruby] ENV[“DATABASE_URL”] = “postgres://localhost/mailer_development” [/ruby]
migrations/*add_queue_classic.rb
[ruby] def up create_table :queue_classic_jobs do |t| t.string :q_name t.string :method t.text :args t.timestamp :locked_at end add_index :queue_classic_jobs, :id end
def down drop_table :queue_classic_jobs end [/ruby]
migrations/*setup_queue_classic.rb
[ruby] def up QC::Queries.load_functions end
def down QC::Queries.drop_functions end [/ruby]
newsletters_controller.rb
[ruby] QC.enqueue “Newsletter.deliver”, params[:id] [/ruby]
models/newsletter.rb
[ruby] def self.deliver(id) newsletter = find(id) # raise “Oops” sleep 10 # simulate long newsletter delivery newsletter.update_attribute(:delivered_at, Time.zone.now) end [/ruby]