brandonhilkert / sucker_punch

Sucker Punch is a Ruby asynchronous processing library using concurrent-ruby, heavily influenced by Sidekiq and girl_friday.
MIT License
2.64k stars 114 forks source link

Scheduling jobs via rake task and whenever fails #183

Closed nynhex closed 8 years ago

nynhex commented 8 years ago

Rails: 3.2.22.4 Ruby: 1.9.3-p194 Sucker Punch: 1.5.1

I have a rake task that I schedule every hour and it fails both in development when being called from the command line and in production when being called from cron.

Where is what the rake task looks like:

lib/tasks/controlled_substance.rake

namespace :controlled_substance do
  desc "Auto-deny any pending controlled substance report after 48 hours" #task describtion
  task :auto_deny => :environment do
     auto_deny
  end

  def auto_deny
    ControlledSubstanceAutoDenyJob.new.async.perform
  end
end

Here is the stacktrace I get when firing the rake task in log/development.log

Terminating 3 actors...
Terminating task: type=:finalizer, meta={:method_name=>:__shutdown__}, status=:receiving
    Celluloid::TaskFiber backtrace unavailable. Please try `Celluloid.task_class = Celluloid::TaskThread` if you need backtraces here.
Connecting to database specified by database.yml
Creating scope :page. Overwriting existing method Audited::Adapters::ActiveRecord::Audit.page.
Connecting to database specified by database.yml
Creating scope :page. Overwriting existing method Audited::Adapters::ActiveRecord::Audit.page.
Terminating 3 actors...
Terminating task: type=:call, meta={:method_name=>:perform}, status=:callwait
    Celluloid::TaskFiber backtrace unavailable. Please try `Celluloid.task_class = Celluloid::TaskThread` if you need backtraces here.
Celluloid::PoolManager: async call `perform` aborted!
Celluloid::Task::TerminatedError: task was terminated
    /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb:34:in `terminate'
    /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/actor.rb:345:in `each'
    /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/actor.rb:345:in `cleanup'
    /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/actor.rb:329:in `shutdown'
    /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/actor.rb:164:in `run'
    /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/actor.rb:130:in `block in start'
    /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/thread_handle.rb:13:in `block in initialize'
    /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/actor_system.rb:32:in `block in get_thread'
    /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/internal_pool.rb:130:in `call'
    /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/internal_pool.rb:130:in `block in create'
Terminating task: type=:finalizer, meta={:method_name=>:__shutdown__}, status=:receiving
    Celluloid::TaskFiber backtrace unavailable. Please try `Celluloid.task_class = Celluloid::TaskThread` if you need backtraces here.
  NarcoticUsage Load (1.2ms)  SELECT "narcotic_usages".* FROM "narcotic_usages" WHERE "narcotic_usages"."status" = 'Pending' AND (created_at < '2016-09-23 10:32:08.382379')

Does this mean the worker actually did something or did it just die on me?

If I cannot schedule the sucker punch job via rake and whenever (cron), how can I schedule a sucker punch job?

brandonhilkert commented 8 years ago

Please update to the latest version of Sucker Punch and see the README for changes.

On Sunday, September 25, 2016, shakycode notifications@github.com wrote:

Rails: 3.2.22.4 Ruby: 1.9.3-p194 Sucker Punch: 1.5.1

I have a rake task that I schedule every hour and it fails both in development when being called from the command line and in production when being called from cron.

Where is what the rake task looks like:

_lib/tasks/controlledsubstance.rake

namespace :controlled_substance do desc "Auto-deny any pending controlled substance report after 48 hours" #task describtion task :auto_deny => :environment do auto_deny end

def auto_deny ControlledSubstanceAutoDenyJob.new.async.perform end end

Here is the stacktrace I get when firing the rake task in log/development.log

Terminating 3 actors... Terminating task: type=:finalizer, meta={:method_name=>:shutdown}, status=:receiving Celluloid::TaskFiber backtrace unavailable. Please try Celluloid.task_class = Celluloid::TaskThread if you need backtraces here. Connecting to database specified by database.yml Creating scope :page. Overwriting existing method Audited::Adapters::ActiveRecord::Audit.page. Connecting to database specified by database.yml Creating scope :page. Overwriting existing method Audited::Adapters::ActiveRecord::Audit.page. Terminating 3 actors... Terminating task: type=:call, meta={:method_name=>:perform}, status=:callwait Celluloid::TaskFiber backtrace unavailable. Please try Celluloid.task_class = Celluloid::TaskThread if you need backtraces here. Celluloid::PoolManager: async call perform aborted! Celluloid::Task::TerminatedError: task was terminated /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb:34:in terminate' /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/actor.rb:345:ineach' /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/actor.rb:345:in cleanup' /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/actor.rb:329:inshutdown' /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/actor.rb:164:in run' /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/actor.rb:130:inblock in start' /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/thread_handle.rb:13:in block in initialize' /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/actor_system.rb:32:inblock in get_thread' /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/internal_pool.rb:130:in call' /Users/shakycode/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/celluloid-0.16.0/lib/celluloid/internal_pool.rb:130:inblock in create' Terminating task: type=:finalizer, meta={:method_name=>:shutdown}, status=:receiving Celluloid::TaskFiber backtrace unavailable. Please try Celluloid.task_class = Celluloid::TaskThread if you need backtraces here. NarcoticUsage Load (1.2ms) SELECT "narcotic_usages".* FROM "narcotic_usages" WHERE "narcotic_usages"."status" = 'Pending' AND (created_at < '2016-09-23 10:32:08.382379')

Does this mean the worker actually did something or did it just die on me?

If I cannot schedule the sucker punch job via rake and whenever (cron), how can I schedule a sucker punch job?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/brandonhilkert/sucker_punch/issues/183, or mute the thread https://github.com/notifications/unsubscribe-auth/AAtbFHCSj3DBKZfvTFfJ1HMrsEMnBI-Yks5qtk85gaJpZM4KF3y1 .


http://brandonhilkert.com

nynhex commented 8 years ago

@brandonhilkert Ok will do. I did notice when I changed my worker to just do a puts, the worker does fire off but and outputs "stuff" to the terminal, but still gives that nasty backtrace in the log.

Here's my worker as just a test.

class ControlledSubstanceAutoDenyJob
  include SuckerPunch::Job

#Add some logging and error handling
  def perform
    ActiveRecord::Base.connection_pool.with_connection do
      puts "stuff"
    end
  end
end
nynhex commented 8 years ago

@brandonhilkert Thanks for the comment, this seems to be working now that I'm on 2.0.2. I'll need to refactor all my worker calls or use the aynsc_syntax in the initializer until I have time to refactor. Appreciate the quick response and awesome gem!

brandonhilkert commented 8 years ago

The newer version of Sidekiq blocks until the job is finished - previous versions didn't. My guess is the job isn't quite down and the thread is being cut-off, resulting in that backtrace.


http://brandonhilkert.com

On Sun, Sep 25, 2016 at 6:43 AM, shakycode notifications@github.com wrote:

@brandonhilkert https://github.com/brandonhilkert Ok will do. I did notice when I changed my worker to just do a puts, the worker does fire off but and outputs "stuff" to the terminal, but still gives that nasty backtrace in the log.

Here's my worker as just a test.

class ControlledSubstanceAutoDenyJob include SuckerPunch::Job

Add some logging and error handling

def perform ActiveRecord::Base.connection_pool.with_connection do puts "stuff" end end end

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/brandonhilkert/sucker_punch/issues/183#issuecomment-249414726, or mute the thread https://github.com/notifications/unsubscribe-auth/AAtbFP0faOltH4upWaAVjqMYbRM7-vM-ks5qtlBPgaJpZM4KF3y1 .