OneshotSimulator

class
Superclass
Symphony::Task

A spike to test out various task execution outcomes.

Public Instance Methods

anchor
work( payload, metadata )

Do the ping.

# File lib/symphony/tasks/oneshot_simulator.rb, line 35
def work( payload, metadata )
        if metadata[:properties][:headers] &&
           metadata[:properties][:headers]['x-death']
                puts "Deaths! %p" % [ metadata[:properties][:headers]['x-death'] ]
        end

        val = Random.rand
        case
        when val < 0.1
                $stderr.puts "Simulating an error in the task (reject)."
                raise "OOOOOPS!"
        when val < 0.15
                $stderr.puts "Simulating a soft failure in the task (reject+requeue)."
                return false
        when val < 0.20
                $stderr.puts "Simulating a timeout case"
                sleep( self.class.timeout + 1 )
        else
                $stderr.puts "Simulating a successful task run (accept)"
                puts( payload.inspect )
                return true
        end
end