Skip to content
This repository
tag: r0.4.1
Fetching contributors…

Cannot retrieve contributors at this time

file 26 lines (20 sloc) 0.57 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

$:.unshift File.dirname(__FILE__) + '/../lib'

require 'procrastinate'

class Worker < Struct.new(:runtime)
  def do_work
    puts "#{Process.pid}: starting..."
    runtime.lock('lock') do
      puts "#{Process.pid}: holds lock"
      sleep 0.1
      puts "#{Process.pid}: releases"
    end
    puts "#{Process.pid}: done."
  end
end

Procrastinate::Lock.base = '/tmp' # This will have to be moved into scheduler
scheduler = Procrastinate::Scheduler.start
worker = scheduler.proxy(Worker.new(scheduler.runtime))

10.times do
  worker.do_work
end

scheduler.shutdown
Something went wrong with that request. Please try again.