1

REXML::elementsidekiq を使用してワーカーに を送信しようとしています。ただし、そうするとエラーが発生します。ActiveSupport::JSON::Encoding::CircularReferenceError

この例では、オンラインで保存されている XML ドキュメントを使用して、それをセクションに分割し、各セクションを処理するサブ ワーカーを作成する 1 つのワーカーを実行しています。

require "rexml/document"
require 'open-uri'
class GroupUploadWorker
  include Sidekiq::Worker
  include REXML

  def perform(user_id, ip_address)
    url = URI.parse('https://s3-us-west-2.amazonaws.com/nick-grn-dev/alldata.xml')
    open(url) do |http|
      @response = http.read
    end
    @doc = Document.new(@response.force_encoding("ISO-8859-1").encode("UTF-8"))
    @doc.root.elements[1].elements.each do |group|
      SingelGroupUploadWorker.perform_async(user_id, ip_address, group)
    end
  end
end

私が見つけた問題は、グループ変数を渡すことです。文字列を渡しても問題なく動作しますが、グループ変数はREXML::Element. エラーを理解するのに十分なほどシステムを理解していないのではないかと心配しています。オンラインでいくつかの調査を行いましたが、正しい質問をしているとは思いません。どんな助けでも大歓迎です。

これにスタック トレースを追加する必要があると誰かが提案しました。私が得ていたエラーはsidekiq自体にあったため、コンソールでエラーを再現するまで、どのように取得するかわかりませんでした. これは、コンソールで発生したものです。

1.9.3p286 :011 > SingelGroupUploadWorker.perform_async(1, '127.0.0.1', @doc.root.elements[1].elements[1])
2013-09-26T01:49:32Z 37015 TID-oxoz25ihc INFO: Sidekiq client using redis://localhost:6379/0 with options {:size=>1}
ActiveSupport::JSON::Encoding::CircularReferenceError: object references itself
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-    3.2.11/lib/active_support/json/encoding.rb:75:in `check_for_circular_references'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:46:in `encode'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:252:in `block in encode_json'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:252:in `each'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:252:in `map'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:252:in `encode_json'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:220:in `block in encode_json'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:220:in `map'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:220:in `encode_json'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:48:in `block in encode'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:77:in `check_for_circular_references'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:46:in `encode'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.11/lib/active_support/json/encoding.rb:31:in `encode'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.11/lib/active_support/core_ext/object/to_json.rb:16:in `to_json'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/json-1.8.0/lib/json/common.rb:223:in `generate'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/json-1.8.0/lib/json/common.rb:223:in `generate'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/sidekiq-2.13.1/lib/sidekiq.rb:97:in `dump_json'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/sidekiq-2.13.1/lib/sidekiq/client.rb:103:in `block (2 levels) in raw_push'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/sidekiq-2.13.1/lib/sidekiq/client.rb:103:in `map'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/sidekiq-2.13.1/lib/sidekiq/client.rb:103:in `block in raw_push'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/connection_pool-1.1.0/lib/connection_pool.rb:49:in `with'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/sidekiq-2.13.1/lib/sidekiq.rb:67:in `redis'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/sidekiq-2.13.1/lib/sidekiq/client.rb:95:in `raw_push'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/sidekiq-2.13.1/lib/sidekiq/client.rb:44:in `push'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/sidekiq-2.13.1/lib/sidekiq/worker.rb:85:in `client_push'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/sidekiq-2.13.1/lib/sidekiq/worker.rb:40:in `perform_async'
from (irb):11
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
from /Users/suddenlyaware/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
4

1 に答える 1