sj26 / cronitor

A Rubygem to interact with Cronitor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cronitor

Travis Gem Version

Cronitor is a service for heartbeat-style monitoring of just about anything that can send an HTTP request.

This gem provides a simple abstraction for the creation and pinging of a Cronitor monitor. For a better understanding of the API this gem talks to, please see How Cronitor Works.

Installation

Add this line to your application's Gemfile:

gem 'cronitor'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cronitor

Usage

Creating a Monitor

A Cronitor monitor (hereafter referred to only as a monitor for brevity) is created if it does not already exist, and its ID returned.

require 'cronitor'

monitor_options = {
  name: 'My Fancy Monitor',
  notifications: {
    emails: ['test@example.com'],
    slack: [],
    pagerduty: [],
    phones: [],
    webhooks: []
  },
  rules: [
    {
      rule_type: 'not_run_in',
      duration: 5
      rime_unit: 'seconds'
    }
  ],
  note: 'A human-friendly description of this monitor'
}
my_monitor = Cronitor.new token: 'api_token', opts: monitor_options

You may optionally specify a :human_readable value for your rule(s), otherwise one will be crafted for you:

monitor_options = {
  rules: [
    {
      rule_type: 'not_run_in',
      duration: 5
      time_unit: 'seconds',
      human_readable: 'not_run_in 5 seconds'
    }
  ],

Pinging a Monitor

Once you’ve created a monitor, you can continue to use the existing instance of the object to ping the monitor that your task status: run, complete, or fail.

my_monitor.ping 'run'
my_monitor.ping 'complete'
my_monitor.ping 'fail', 'A short description of the failure'

Pinging a monitor when you have a Cronitor code

You may already have the code for a monitor, in which case, the expense of Cronitor.new may seem unnecessary (since it makes an HTTP request to check if a monitor exists, and you already know it does).

In that case:

my_monitor = Cronitor.new code: 'abcd'

The aforementioned ping methods can now be used.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

  1. Fork it ( https://github.com/evertrue/cronitor/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

Release a new version

The bump gem makes this easy:

  1. rake bump:(major|minor|patch|pre)
  2. rake release

About

A Rubygem to interact with Cronitor

License:MIT License


Languages

Language:Ruby 99.1%Language:Shell 0.9%