bundle exec sidekiq -etest
test "should execute action when executed" do ps = PathState.create(:name => "TestName", :action => "touch /tmp/PathStateTest") ps.execute result = `[ -f /tmp/PathStateTest ] && echo 0 || echo 1` assert result==0, "OOPS! PathState doesn't execute action when executed!" end
class PathState < ActiveRecord::Base
validates :name, presence: true
def execute PathStateRunner.perform_async(id) endend
class PathStateRunner include Sidekiq::Worker
sidekiq_options :retry => 2, :backtrace => true # job will retry according to retry mechanism specified
sidekiq_retry_in do |count| 15 * (count + 1) # (i.e. 15, 30, 45) end
sidekiq_retries_exhausted do |msg| Sidekiq.logger.warn "---> Failed #{msg['class']} with #{msg['args']}: #{msg['error_message']}" end
def perform(path_state_id) ps = PathState.find(path_state_id)
@result = `#{ps.action} 2>&1` unless $?.exitstatus.zero? # failed state Sidekiq.logger.warn "---> PathStateRunner worker failed action: '#{ps.action}'" end endend
--
You received this message because you are subscribed to the Google Groups "Sidekiq" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sidekiq+u...@googlegroups.com.
To post to this group, send email to sid...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sidekiq/d809fa09-7840-4c66-b995-fdf1d97222fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Sidekiq" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sidekiq+u...@googlegroups.com.
To post to this group, send email to sid...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sidekiq/d41cda0a-4c7b-4d78-bd46-91a14906eef6%40googlegroups.com.