这就是我在NoteWorker中使用rake任务启动的功能。
NoteWorker.rb
class NoteWorker
include Sidekiq::Worker
sidekiq_options queue: "note"
sidekiq_options :failures => true
def perform(model_id)
#do something
end
end
note.rake
namespace :notes do
task :send_note => :environment do
NoteWorker.perform_async(model.id)
end
end
一切都按原样运作。但我正在尝试自动缩放,这似乎无法自动调整多个工作程序,所以我试图将所有队列更改为“默认”而不是自定义名称。但是当我删除sidekiq_options queue: "note"
或将其更改为sidekiq_options queue: "default"
时,它会给我这个错误:
"Scaling worker to 1"
rake aborted!
Expected(200) <=> Actual(404 Not Found)
request => {:connect_timeout=>60, :headers=>{"Accept"=>"application/json", "Accept-Encoding"=>"gzip", "Authorization"=>"Basic Og==", "User-Agent"=>"heroku-rb/0.2.1", "X-Heroku-API-Version"=>"3", "X-Ruby-Version"=>"1.9.3", "X-Ruby-Platform"=>"x86_64-darwin10.8.0", "Host"=>"api.heroku.com:443", "Content-Length"=>0}, :instrumentor_name=>"excon", :mock=>false, :read_timeout=>60, :retry_limit=>4, :ssl_ca_file=>"/Users/user/.rvm/gems/ruby-1.9.3-p0@notebook/gems/excon-0.13.4/data/cacert.pem", :ssl_verify_peer=>true, :write_timeout=>60, :host=>"api.heroku.com", :path=>"/apps//ps/scale", :port=>"443", :query=>{"type"=>"worker", "qty"=>1}, :scheme=>"https", :expects=>200, :method=>:post}
response => #<Excon::Response:0x00000104700aa8 @body="{\"id\":\"not_found\",\"error\":\"Not found\"}", @headers={"Cache-Control"=>"no-transform", "Content-Type"=>"application/json;charset=utf-8", "Date"=>"Wed, 31 Jul 2013 02:32:25 GMT", "Status"=>"404 Not Found", "Strict-Transport-Security"=>"max-age=31536000", "X-Cascade"=>"pass", "X-Content-Type-Options"=>"nosniff", "X-Runtime"=>"0.00246243", "Content-Length"=>"38", "Connection"=>"keep-alive"}, @status=404>
/Users/user/.rvm/gems/ruby-1.9.3-p0@notebook/gems/excon-0.13.4/lib/excon/connection.rb:266:in `request_kernel'
/Users/user/.rvm/gems/ruby-1.9.3-p0@notebook/gems/excon-0.13.4/lib/excon/connection.rb:97:in `request'
/Users/user/.rvm/gems/ruby-1.9.3-p0@notebook/gems/heroku-api-0.2.1/lib/heroku/api.rb:60:in `request'
/Users/user/.rvm/gems/ruby-1.9.3-p0@notebook/gems/heroku-api-0.2.1/lib/heroku/api/processes.rb:43:in `post_ps_scale'
/Users/user/.rvm/gems/ruby-1.9.3-p0@notebook/gems/autoscaler-0.3.0/lib/autoscaler/heroku_scaler.rb:38:in `workers='
/Users/user/.rvm/gems/ruby-1.9.3-p0@notebook/gems/autoscaler-0.3.0/lib/autoscaler/sidekiq/client.rb:14:in `call'
/Users/user/.rvm/gems/ruby-1.9.3-p0@notebook/gems/sidekiq-2.8.0/lib/sidekiq/middleware/chain.rb:111:in `block in invoke'
/Users/user/.rvm/gems/ruby-1.9.3-p0@notebook/gems/sidekiq-2.8.0/lib/sidekiq/middleware/chain.rb:114:in `call'
/Users/user/.rvm/gems/ruby-1.9.3-p0@notebook/gems/sidekiq-2.8.0/lib/sidekiq/middleware/chain.rb:114:in `invoke'
/Users/user/.rvm/gems/ruby-1.9.3-p0@notebook/gems/sidekiq-2.8.0/lib/sidekiq/client.rb:112:in `process_single'
/Users/user/.rvm/gems/ruby-1.9.3-p0@notebook/gems/sidekiq-2.8.0/lib/sidekiq/client.rb:40:in `push'
/Users/user/.rvm/gems/ruby-1.9.3-p0@notebook/gems/sidekiq-2.8.0/lib/sidekiq/worker.rb:68:in `client_push'
/Users/user/.rvm/gems/ruby-1.9.3-p0@notebook/gems/sidekiq-2.8.0/lib/sidekiq/worker.rb:38:in `perform_async'
/Users/user/rails_projects/notebook/lib/tasks/send_note.rake:25:in `block (3 levels) in <top (required)>'
/Users/user/.rvm/gems/ruby-1.9.3-p0@notebook/gems/activerecord-3.2.12/lib/active_record/relation/delegation.rb:6:in `each'
/Users/user/.rvm/gems/ruby-1.9.3-p0@notebook/gems/activerecord-3.2.12/lib/active_record/relation/delegation.rb:6:in `each'
/Users/user/rails_projects/notebook/lib/tasks/send_note.rake:24:in `block (2 levels) in <top (required)>'
Tasks: TOP => send_note:send_note
(See full trace by running task with --trace)