3
votes

I wanted to get started with resque. So I created three files, one to create a dummy job, the other two to handle it:


    --- 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'

Then I first execute $ ruby create_job.rb without problems. I can see the job in the resque queue.

Now I want to start a worker - but that fails:


    $ 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

Does somebody have a clue what's going on? It looks like some encoding problem, but where?

I use Windows 7 (if that's relevant).

EDIT: I inserted debug output into the '#encode' method: {:queue=>"image_transform_queue", :run_at=>"2012/03/28 13:25:53 Mitteleurop\xE4i sche Sommerzeit", :payload=>{"class"=>"ImageTransformer", "args"=>["test"]}}

Apparently the problem is that the ":run_at" value contains a German umlaut (that's my locale).

1
Can you make a minimalistic runnable version that reproduces the problem and which we can try? - Sergio Tulentsev
Good job! You should post this as an answer. - Sergio Tulentsev
Resque is serializing the payload using the multi_json gem -- It calls MultiJson.dump and MultiJson.load. multi_json allows swapping of JSON engine. By default, it uses JsonGem, which has an issue with these characters (umlaut, emoji, etc). I haven't tried, but perhaps you can try swapping for Oj like this: MultiJson.use(:oj) - awaage

1 Answers

0
votes

To get it off the unanswered list:


I inserted debug output into the '#encode' method:

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

Apparently the problem is that the :run_at value contains a German umlaut (that's my locale).