Sha256: e2e55a29866ed1181c7f9031aff0f8ef2eb97de5ca1259808c948518038d8ffe

Contents?: true

Size: 1.45 KB

Versions: 7

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 = ThreadedVisor.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

7 entries across 7 versions & 1 rubygems

Version Path
kryten-0.3.9 bin/console
kryten-0.3.8 bin/console
kryten-0.3.7 bin/console
kryten-0.3.6 bin/console
kryten-0.3.5 bin/console
kryten-0.3.4 bin/console
kryten-0.3.3 bin/console