Blender::Zk

Zookeeper integration for blender. It allows Blender to use zookeeper for locking. Blender jobs running in different nodes can synchornize/coordinate using zookeeper.

Installation

Add this line to your application's Gemfile:

gem 'blender-zk'

And then execute:

$ bundle

Or install it yourself as:

$ gem install blender-zk

Usage

  • Blender by default used file based locking (flock/fcntl) for locking. You have to explicitly tell blender to use zookeeper locking interface. This can be done using the lock_options DSL method. It take the locking driver name ('zk' in our case).
Blender.blend('test-1') do |sched|
  sched.members(['localhost'])
  sched.lock_options('zk')
  sched.ruby_task('date') do
    execute do
      sleep 10
      puts 'This will succeed'
    end
  end
end

## in another script
Blender.blend('test-1') do |sched|
  sched.members(['localhost'])
  sched.lock_options('zk')
  sched.ruby_task('date') do
    execute do
      puts 'This will fail, if both jobs are triggered at the same time '
    end
  end
end

By default blender-zk will use the job name 'test-1' as key name. This, and other options (lock wait timeout, chroot etc) can be passed as option

Blender.blend('test-1') do |sched|
  sched.members(['localhost'])
  sched.lock_options('zk', path: '/path/to/lock')
  sched.ruby_task('date') do
    execute do
      sleep 3
    end
  end
end
### in another script
Blender.blend('test-2') do |sched|
  sched.members(['localhost'])
  sched.lock_options('zk', path: '/path/to/lock', timeout: 5)
  sched.ruby_task('date') do
    execute do
      puts 'This wont fail, since it will wait 5 second, by then the first job will finish'
    end
  end
end

License

Apache 2

Contributing

  1. Fork it ( https://github.com/[my-github-username]/blender-zk/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request