retryit 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -1
  3. data/lib/retryit.rb +24 -3
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be1aa72d40e7c8badd21382d2c3fd41ee6579b26
4
- data.tar.gz: 2e9d14f94fec8bbf040b08c2fa462ed105ec6794
3
+ metadata.gz: af8eac7556a4bcd9b925a05bf1a28e3fa315dc53
4
+ data.tar.gz: 01eabeca7d901247988c8596236edae1ea819a09
5
5
  SHA512:
6
- metadata.gz: 23ca9102779a73de3f60b3221021de7614d186305b0ec217f3ce85fde07b8774bc971f785d4b0d72d93075351f22539a19aa13d993cd94cea07b2094e5ed8124
7
- data.tar.gz: dd75f23f180fe7aae37dbac236e7dbc05a01dcd62876af85e74e41344b7bfef7da2f53b105f9cd512a0a63cc5505f29482e0225ca80691a45671489fa842df6a
6
+ metadata.gz: b0b77b2c8329a1a419e5727fa3773788a477e5cd4655b30a5e193746b3f267d8f2c092b57bd6784d68242fb8204e4e710b4b07d387085c5be563a6b04bfe8dd5
7
+ data.tar.gz: 9b48898e4dfda35ab1b704798225f6b8d23699cf569915e4a0154ea0d508acc290c63048244e130d53899fb079aa0bd400e093e90fa633f14e735b1d483e99a0
data/README.md CHANGED
@@ -15,8 +15,9 @@ Help:
15
15
 
16
16
  `retry -?`
17
17
 
18
- Usage: retry [options] -e execute command
18
+ Usage: retry [options] [-f fail_script +commands] -e execute command
19
19
  -h, -?, --help
20
+ -f Execute fail script after all retries are exhausted
20
21
  -t, --tries=# Set max retries: Default 10
21
22
  -s, --sleep=secs Constant sleep amount (seconds)
22
23
  -m, --min=secs Exponenetial Backoff: minimum sleep amount (seconds): Default 0.3
@@ -24,6 +25,12 @@ Help:
24
25
 
25
26
  ### Examples
26
27
 
28
+ No problem:
29
+
30
+ `retry echo u work good`
31
+
32
+ u work good
33
+
27
34
  Test functionality:
28
35
 
29
36
  `retry 'echo "y u no work"; false'`
@@ -49,6 +56,7 @@ Test functionality:
49
56
  y u no work
50
57
  Before retry #10: sleeping 60.0 seconds
51
58
  y u no work
59
+ etc..
52
60
 
53
61
  Limit retries:
54
62
 
@@ -63,6 +71,7 @@ Limit retries:
63
71
  y u no work
64
72
  Before retry #4: sleeping 2.4 seconds
65
73
  y u no work
74
+ Retries exhausted
66
75
 
67
76
  Bad command:
68
77
 
@@ -70,6 +79,20 @@ Bad command:
70
79
 
71
80
  Command Failed: poop
72
81
 
82
+ Fail command:
83
+
84
+ `retry -t 3 -f echo "oh poopsickles" -e 'echo "y u no work"; false'`
85
+
86
+ y u no work
87
+ Before retry #1: sleeping 0.3 seconds
88
+ y u no work
89
+ Before retry #2: sleeping 0.6 seconds
90
+ y u no work
91
+ Before retry #3: sleeping 1.2 seconds
92
+ y u no work
93
+ Retries exhausted, running fail script
94
+ oh poopsickles
95
+
73
96
  ### License
74
97
 
75
98
  Apache 2.0 - go nuts
@@ -16,7 +16,7 @@ class RetryIt
16
16
  return if args.size < 1
17
17
 
18
18
  optparser = OptionParser.new do |opts|
19
- opts.banner = "Usage: retry [options] -e execute command"
19
+ opts.banner = "Usage: retry [options] [-f fail_script +commands] -e execute command"
20
20
 
21
21
  opts.on("-h", "-?", "--help") do |v|
22
22
  puts opts
@@ -58,12 +58,24 @@ class RetryIt
58
58
  load_options(["-?"])
59
59
  end
60
60
 
61
- idx = args.find_index("-e")
61
+ fail_command = nil
62
+
63
+ idx = args.find_index("-f") || args.find_index("-e")
62
64
  if !idx.nil?
63
65
  load_options(args[0...idx])
66
+ if (args[idx] == "-f")
67
+ e_idx = args.find_index("-e")
68
+ raise "fail script (-f) must be combined with execution script (-e)" if e_idx.nil?
69
+ raise "fail script not defined" if idx == e_idx
70
+ fail_command = args[(idx+1)..(e_idx-1)]
71
+ idx = e_idx
72
+ end
64
73
  args = args[(idx+1)..-1]
65
74
  end
66
75
 
76
+ #log_out("Run script #{args[0]} #{args[1..-1]}")
77
+ #log_out("Fail script #{fail_command[0]} #{fail_command[1..-1]}") unless fail_command.nil?
78
+
67
79
  raise "max_tries must be greater than 0" unless @max_tries > 0
68
80
  raise "minimum sleep cannot be greater than maximum sleep" unless @max_sleep >= @min_sleep
69
81
  raise "unknown execute command" unless args.size > 0
@@ -82,7 +94,16 @@ class RetryIt
82
94
  attempts += 1
83
95
  end
84
96
 
85
- log_out("Command Failed: #{args[0]}") if success.nil?
97
+ if success.nil?
98
+ log_out("Command Failed: #{args[0]}")
99
+ elsif attempts > @max_tries
100
+ if !fail_command.nil?
101
+ log_out("Retries exhausted, running fail script")
102
+ system(fail_command[0], *fail_command[1..-1])
103
+ else
104
+ log_out("Retries exhausted")
105
+ end
106
+ end
86
107
  exit process.exitstatus
87
108
  end
88
109
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retryit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neville Kadwa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-26 00:00:00.000000000 Z
11
+ date: 2015-06-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: General purpose retry cli program for anything
14
14
  email: