README.md in zhong-0.2.2 vs README.md in zhong-0.2.3

- old
+ new

@@ -2,20 +2,24 @@ Useful, reliable distributed cron. Tired of your cron-like scheduler running key jobs twice? Would you like to be able to run your cron server on multiple machines and have it "just work"? Have we got the gem for you. Zhong uses Redis to acquire exclusive locks on jobs, as well as recording when they last ran. This means that you can rest easy at night, knowing that your customers are getting their monthly Goat Fancy magazine subscriptions and you are rolling around in your piles of money without a care in the world. +:tangerine: Battle-tested at [Instacart](https://www.instacart.com/opensource) # Installation Add this line to your application’s Gemfile: ```ruby gem 'zhong' ``` ## Usage +### Zhong schedule +Create a definition file, let's call it `zhong.rb`: + ```ruby Zhong.redis = Redis.new(url: ENV["ZHONG_REDIS_URL"]) Zhong.schedule do category "stuff" do @@ -73,21 +77,58 @@ puts "dang, #{job} messed up: #{e}" end end ``` +This file only describes what should be the schedule. Nothing will be executed +until we actually run +```ruby +Zhong.start +``` +after describing the Zhong schedule. + +### Zhong cron process + +You can run the cron process that will execute your code from the definitions +in the `zhong.rb` file by running: +```sh +zhong zhong.rb +``` + ## Web UI Zhong comes with a web application that can display jobs, their last run and enable/disable them. -### Rails +This is a Sinatra application that requires at least `v2.0.0`. You can add to your Gemfile +```ruby +gem 'sinatra', "~>2.0" +``` -Add the following to your config/routes.rb: +It can be protected by HTTP basic authentication by +setting the following environment variables: +- `ZHONG_WEB_USERNAME`: the username +- `ZHONG_WEB_PASSWORD`: the password +You'll need to load the Zhong schedule to be able to see jobs in the web UI, typically +by requiring your `zhong.rb` definition file. + +### Rails +Load the Zhong schedule by creating an initializer at `config/initializers/zhong.rb`, +with the following content: ```ruby +require "#{Rails.root}/zhong.rb" +``` + +Add the following to your `config/routes.rb`: +```ruby require 'zhong/web' -mount Zhong::Web, at: "zhong" + +Rails.application.routes.draw do + # Other routes here... + + mount Zhong::Web, at: "/zhong" +end ``` ## History View the [changelog](https://github.com/nickelser/zhong/blob/master/CHANGELOG.md).