attempt

Version, currently 0.1.01 version
  • 0.1.0latestJan 30, 2017

github.com/mosop/attempt

A tiny Crystal library for trying code blocks again and again.

0 stars
1 dependent
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  attempt:
    github: mosop/attempt
    version: ~> 0.1.0

Then run:

shards install

shard.yml

Crystal
0.20.5
License
MIT
Author
mosop

Dependencies

Runtime Dependencies

  • calling~> 0.1.0github: mosop/calling

Development Dependencies

  • stdio~> 0.1.3github: mosop/stdiodev

README

Attempt

A tiny Crystal library for trying code blocks again and again.

Build Status

Installation

Add this to your application's shard.yml:

dependencies:
  attempt:
    github: mosop/attempt

Code Samples

Trying 5 Times

response = Attempt.times(5).start do
  begin
    response = HTTP::Client.get("http://unstable.net")
    break response if response.success?
  rescue
  end
end

if response
  puts response.body
else
  raise "UNSTABLE!"
end

Wait 60 Sec. Before a Retry

response = Attempt.times(5).wait(60).start do
  begin
    response = HTTP::Client.get("http://unstable.net")
    break response if response.success?
  rescue
  end
end

Every Hour Forever

Attempt.wait(60 * 60).start do
  begin
    response = HTTP::Client.get("http://api.cat.pics/links.json")
    File.write("/path/to/kitty.json", response.body) if response.success?
  rescue
  end
end

Wait 10 Sec. Before the First Attempt

`rails s`
response = Attempt.prewait(10).start do
  begin
    response = HTTP::Client.get("http://localhost:3000")
    break response if response.success?
  rescue
  end
end

Usage

require "attempt"