CronR 0.1.4 → 0.1.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5bf402529ecd7ebee8d859c478097caeb4c7cba
4
- data.tar.gz: 7673acb5eff3379c352bfa2c000541b394e1199d
3
+ metadata.gz: aba2673998541390349e2c859d1fb796c9350d2a
4
+ data.tar.gz: 3ae6120d76daa6531c349483a9e3ddc02320bcd4
5
5
  SHA512:
6
- metadata.gz: 75736376f3bd20879fbc8c850b39efb20251b9e3e364fc393e8e9960597c05e0bb8895059419296042199d1660f92250e5d0c9f162dc8272057a470aac3e0a0f
7
- data.tar.gz: 8e3711b87137ae5d03d7c58c721bbaf341f3c2b0d3b3bfd361d4149d3d31e16b2542cba1d339267828dcb975751e9f02b848b0a92aa4f69cb9d90bd532bbf3d7
6
+ metadata.gz: 722679cce5b117e2f7994fc660cbe488271f1ff697b5e2a568d3a8c130c884e60f100d891a78401a138256ea8c7bc21feddc47bf3bbd67f5f940d5786596e2bd
7
+ data.tar.gz: acf5be4c58347d60842325aad87c14c354f65824834b2957299a4d82557293d96612511f13ca4983069a1ae8c1945389dbb218ffc428c5c4376c00022e20b877
@@ -19,6 +19,12 @@ module CronR
19
19
  # cp.job = {...} => a non-proc job
20
20
  #
21
21
  # CRON PARAMETERS:
22
+ #
23
+ # CronR parameters are represented as either:
24
+ #
25
+ # i) booleans = '*'
26
+ # ii) Fixnums = 'n' where n is an integer
27
+ # iii) Array = 'n-m' 'n,m' 'n-m/k' 'n-m,o-p'
22
28
  #
23
29
  # cp[s] where s can be :minute,:hour,:day,:dow,:month .
24
30
  #
@@ -5,8 +5,59 @@
5
5
  # LICENSE.txt.
6
6
 
7
7
  module CronR
8
+
8
9
  module Utils
9
10
 
11
+ # Parse a single cron parameter into a format that CronR uses.
12
+ #
13
+ # Currently not used directly by CronR. But may be handy for
14
+ # translating cron parameters.
15
+ #
16
+ # '*' => true
17
+ # '1' => 1
18
+ # '1-3' => [1,2,3]
19
+ # Other forms which translate to arrays:
20
+ # '*/3' '1-5/2' '2,4,8' '2-4,6-8'
21
+ #
22
+ # In the case of */3 we do: (1..59).step(3).to_a
23
+ # which will hopefully cover all cases.
24
+
25
+ def self.parse_param str
26
+ parts = str.split(',')
27
+ if parts.empty? || parts.detect{|i| i.empty? } then
28
+ raise "Not enough information to process parameter: '#{str}'."
29
+ end
30
+ parts.map { |p|
31
+ n, step = p.split('/')
32
+ raise "No number before slash: '#{str}'" if n.empty?
33
+ a, b = n.split('-')
34
+ raise "No number before hyphen: '#{str}'" if a.empty?
35
+ a = a.strip
36
+ raise "Not a number or asterisk: '#{a}'" unless /^\d+$|^\*$/ === a
37
+ if b then
38
+ a, b = a.to_i, b.to_i
39
+ if step then
40
+ (a..b).step(step.to_i).to_a
41
+ else
42
+ (a..b).to_a
43
+ end
44
+ else
45
+ case a
46
+ when '*'
47
+ if step then
48
+ # Bit cheap, basically we'll cover ourselves for all
49
+ # component types by going up to 59
50
+ (0..59).step(step.to_i).to_a
51
+ else
52
+ return true # ick, exit def
53
+ end
54
+ else
55
+ [a.to_i]
56
+ end
57
+ end
58
+ }.flatten
59
+ end
60
+
10
61
  # Wake up every minute and call &block.
11
62
  #
12
63
  # Returns the thread that does the waking up.
@@ -18,7 +69,7 @@ module CronR
18
69
  Thread.new {
19
70
  now = Time.now
20
71
  wait = secs-now.sec-now.usec.to_f/mil
21
- p "[every_minute] sleeping #{wait}" if debug
72
+ #p "[every_minute] sleeping #{wait}" if debug
22
73
  sleep wait
23
74
  loop {
24
75
  result = block.call
@@ -27,7 +78,7 @@ module CronR
27
78
  end
28
79
  now = Time.now
29
80
  wait = secs-now.sec-now.usec.to_f/mil
30
- p "[every_minute] sleeping #{wait}" if debug
81
+ #p "[every_minute] sleeping #{wait}" if debug
31
82
  sleep(wait)
32
83
  }
33
84
  }
@@ -45,7 +96,7 @@ module CronR
45
96
  if result==true then
46
97
  break
47
98
  end
48
- p "[every] sleeping #{secs}" if debug
99
+ #p "[every] sleeping #{secs}" if debug
49
100
  sleep secs
50
101
  }
51
102
  }
@@ -121,4 +172,5 @@ module CronR
121
172
  end
122
173
 
123
174
  end
175
+
124
176
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: CronR
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bush
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-03 00:00:00.000000000 Z
11
+ date: 2014-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport