Sha256: 795dd6d52864bc147a89110c85ea7fb4ef23ab2f7424a835e4f2cba3cdf3262a
Contents?: true
Size: 1.45 KB
Versions: 3
Compression:
Stored size: 1.45 KB
Contents
#!/usr/bin/env ruby require "bundler/setup" require "kryten" require "pry" include Kryten class WorkList include BackgroundTask end class Work include BackgroundTask def run work = rand(5)+1; log "working for #{work}" sleep work log "done working" end def timer 0.1 end end class ThreadedWork include ThreadedTask def run work = rand(5)+1; log "working for #{work}" sleep work log "done working" end def timer 0.1 end end work = WorkList.new('visor').workers do [ Work.new('work1'), Work.new('work2'), Work.new('work3').workers do [ Work.new('work3sub1'), Work.new('work3sub2') ] end ] end threaded_work = ThreadVisor.workers do [ ThreadedWork.new('thread work1'), ThreadedWork.new('thread work2'), ThreadedWork.new('thread work3').workers do [ ThreadedWork.new('thread work3sub1'), ThreadedWork.new('thread work3sub2') ] end ] end mixed_work = Work.new('mixy').mixed.workers do [ Work.new('mixy 1 process').workers do Work.new('mixy 1 subprocess') end, ThreadedWork.new('mixy 2 thread').workers do ThreadedWork.new('mixy2 subthread') end ] end class CrashWork include BackgroundTask def run sleep rand(3) + 2 log 'working' raise 'boom' if rand(5) == 0 end end crashing_work = CrashWork.new('crashy').workers do [ Work.new('regular1'), Work.new('regular2'), CrashWork.new('crash3') ] end binding.pry #w3.start
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
kryten-0.3.2 | bin/console |
kryten-0.3.1 | bin/console |
kryten-0.3.0 | bin/console |