rake resque:工作失败,简单的例子

时间:2012-03-28 10:29:30

标签: ruby encoding rake resque

我想开始使用resque。所以我创建了三个文件,一个用于创建虚拟作业,另外两个用于处理它:


    --- image_transformer.rb ---
    # coding: UTF-8
    class ImageTransformer
      @queue = 'image_transform_queue'

      def self.perform(asset_id)
        puts "perform"
        puts asset_id
      end
    end


    --- create_job.rb ---
    # coding: UTF-8
    require 'resque'
    require_relative 'image_transformer'

    Resque.enqueue(ImageTransformer, 'test')


    --- Rakefile ---
    # coding: UTF-8
    require_relative 'image_transformer'
    require 'resque/tasks'

然后我首先执行$ ruby​​ create_job.rb而没有问题。我可以在resque队列中看到这份工作。

现在我想开始一个工人 - 但是失败了:


    $ QUEUE=* VVERBOSE=1 VERBOSE=1 rake resque:work --trace
    ** Invoke resque:work (first_time)
    ** Invoke resque:preload (first_time)
    ** Invoke resque:setup (first_time)
    ** Execute resque:setup
    ** Execute resque:preload
    ** Invoke resque:setup
    ** Execute resque:work
    *** Starting worker anpr-THINK:15292:*
    Signals QUIT, USR1, USR2, and/or CONT not supported.
    *** Registered signals
    *** Checking content_download
    *** Checking image_transform_queue
    *** Found job on image_transform_queue
    *** got: (Job{image_transform_queue} | ImageTransformer | ["test"])
    rake aborted!
    "\xE4" on US-ASCII
    c:/ruby193/lib/ruby/gems/1.9.1/gems/multi_json-1.2.0/lib/multi_json/engines/json
    _common.rb:13:in `encode'
    c:/ruby193/lib/ruby/gems/1.9.1/gems/multi_json-1.2.0/lib/multi_json/engines/json
    _common.rb:13:in `to_json'
    c:/ruby193/lib/ruby/gems/1.9.1/gems/multi_json-1.2.0/lib/multi_json/engines/json
    _common.rb:13:in `encode'
    c:/ruby193/lib/ruby/gems/1.9.1/gems/multi_json-1.2.0/lib/multi_json.rb:88:in `en
    code'
    c:/ruby193/lib/ruby/gems/1.9.1/gems/resque-1.20.0/lib/resque/helpers.rb:22:in `e
    ncode'
    c:/ruby193/lib/ruby/gems/1.9.1/gems/resque-1.20.0/lib/resque/worker.rb:396:in `w
    orking_on'
    c:/ruby193/lib/ruby/gems/1.9.1/gems/resque-1.20.0/lib/resque/worker.rb:133:in `b
    lock in work'
    c:/ruby193/lib/ruby/gems/1.9.1/gems/resque-1.20.0/lib/resque/worker.rb:126:in `l
    oop'
    c:/ruby193/lib/ruby/gems/1.9.1/gems/resque-1.20.0/lib/resque/worker.rb:126:in `w
    ork'
    c:/ruby193/lib/ruby/gems/1.9.1/gems/resque-1.20.0/lib/resque/tasks.rb:34:in `blo
    ck (2 levels) in '
    c:/ruby193/lib/ruby/1.9.1/rake/task.rb:205:in `call'
    c:/ruby193/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute'
    c:/ruby193/lib/ruby/1.9.1/rake/task.rb:200:in `each'
    c:/ruby193/lib/ruby/1.9.1/rake/task.rb:200:in `execute'
    c:/ruby193/lib/ruby/1.9.1/rake/task.rb:158:in `block in invoke_with_call_chain'
    c:/ruby193/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
    c:/ruby193/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
    c:/ruby193/lib/ruby/1.9.1/rake/task.rb:144:in `invoke'
    c:/ruby193/lib/ruby/1.9.1/rake/application.rb:116:in `invoke_task'
    c:/ruby193/lib/ruby/1.9.1/rake/application.rb:94:in `block (2 levels) in top_lev
    el'
    c:/ruby193/lib/ruby/1.9.1/rake/application.rb:94:in `each'
    c:/ruby193/lib/ruby/1.9.1/rake/application.rb:94:in `block in top_level'
    c:/ruby193/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handlin
    g'
    c:/ruby193/lib/ruby/1.9.1/rake/application.rb:88:in `top_level'
    c:/ruby193/lib/ruby/1.9.1/rake/application.rb:66:in `block in run'
    c:/ruby193/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handlin
    g'
    c:/ruby193/lib/ruby/1.9.1/rake/application.rb:63:in `run'
    c:/ruby193/bin/rake:32:in `'
    Tasks: TOP => resque:work

有人知道发生了什么吗?它看起来像是一些编码问题,但在哪里呢?

我使用的是Windows 7(如果相关的话)。

编辑: 我将调试输出插入'#encode'方法: {:queue =>“image_transform_queue”,:run_at =>“2012/03/28 13:25:53 Mitteleurop \ xE4i sche Sommerzeit“,:payload => {”class“=>”ImageTransformer“,”args“=> [”test“]}}

显然问题是“:run_at”值包含一个德语变音符号(这是我的语言环境)。

1 个答案:

答案 0 :(得分:0)

将其从未答复的清单中删除:


我将调试输出插入'#encode'方法:

{
    :queue=>"image_transform_queue",
    :run_at=>"2012/03/28 13:25:53 Mitteleurop\xE4i sche Sommerzeit",
    :payload=>{"class"=>"ImageTransformer", "args"=>["test"]}
}

显然问题是:run_at值包含德语变音符号(这是我的语言环境)。