collectiveidea / delayed_job

Database based asynchronous priority queue system -- Extracted from Shopify
http://groups.google.com/group/delayed_job
MIT License
4.82k stars 954 forks source link

Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'. #727

Open smlsml opened 10 years ago

smlsml commented 10 years ago

My Delayed::Job workers do not start on Chinese Windows.

I get this error:

ActiveRecord::StatementInvalid: ODBC::Error: 37000 (214) [Microsoft][ODBC SQL Server Driver][SQL Server]Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.: EXEC sp_executesql 'UPDATE [delayed_jobs] SET [locked_by] = NULL, [locked_at] = NULL WHERE [delayed_jobs].[locked_by] = N''host:测试用户-PC pid:608''; SELECT @@ROWCOUNT AS AffectedRows'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:389:in `run'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:389:in `block in raw_connection_run'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver_adapter.rb:505:in `with_sqlserver_error_handling'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:384:in `raw_connection_run'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:376:in `_raw_select'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:371:in `block in raw_select'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.19/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:371:in `raw_select'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:354:in `do_exec_query'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:24:in `exec_query'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/database_statements.rb:77:in `exec_update'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:39:in `exec_update'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/database_statements.rb:96:in `update'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `update'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.19/lib/active_record/relation.rb:294:in `update_all'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/delayed_job_active_record-0.4.4/lib/delayed/backend/active_record.rb:40:in `clear_locks!'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/plugins/clear_locks.rb:9:in `ensure in block (2 levels) in <class:ClearLocks>'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/plugins/clear_locks.rb:9:in `block (2 levels) in <class:ClearLocks>'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:78:in `call'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:78:in `block (2 levels) in add'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:60:in `call'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:60:in `block in initialize'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:78:in `call'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:78:in `block in add'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:65:in `call'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:65:in `execute'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:38:in `run_callbacks'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/worker.rb:147:in `start'
C:/Program Files (x86)/****/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/tasks.rb:9:in `block (2 levels) in <top (required)>'

After much experimentation I was able to fix the problem with this monkey patch.

# Encoding.locale_charmap was "CP936" on the test system
module Delayed
  class Worker
    def name
      return @name unless @name.nil?
      "#{@name_prefix}host:#{Socket.gethostname.force_encoding(Encoding.locale_charmap).encode('utf-8')} pid:#{Process.pid}" rescue "#{@name_prefix}pid:#{Process.pid}"
    end
  end
end

I wanted to post this quickly in case anyone else ever has this problem. I'll try to remember to come back and make a pull request.

ridiculous commented 7 years ago

Any plans on that PR?