Skip to content

Commit

Permalink
Merge pull request #21 from AntoineAugusti/improve-readme
Browse files Browse the repository at this point in the history
README: definition, cron process, web UI
  • Loading branch information
nickelser committed Jul 28, 2017
2 parents 176d854 + ab8f063 commit b459627
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ 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"])

Expand Down Expand Up @@ -76,18 +79,55 @@ Zhong.schedule do
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"
```

It can be protected by HTTP basic authentication by
setting the following environment variables:
- `ZHONG_WEB_USERNAME`: the username
- `ZHONG_WEB_PASSWORD`: the password

Add the following to your config/routes.rb:
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
Expand Down

0 comments on commit b459627

Please sign in to comment.