robodash 0.2.0 → 0.3.0
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 +4 -4
- data/lib/robodash/version.rb +1 -1
- data/lib/robodash.rb +34 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddd20a1df16bb150163a7c2d2681ca0cd63b4cbe2100801087eba5f4536bbe8d
|
4
|
+
data.tar.gz: a2c185bc91ee8f1e5759ed8bbbad4254e5ab7c9ca03e41b99cce37446c3cae26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49c2472b56fa3983f4c3628a399b0be585189a7260f9e4947874905f257e3fc9a8f32dd4c5832466d17310facd2a93dd60d9630ac1f0528f9f645bc2d7bb125e
|
7
|
+
data.tar.gz: ea6b47792eb289f1942d3199e7f4808f9215a3d25ac22034fd66fa19e4c56309214817cf58ff8f29667db3e65c021dcb53419123cb0ce84bf6aa1af1322b7a0f
|
data/lib/robodash/version.rb
CHANGED
data/lib/robodash.rb
CHANGED
@@ -11,6 +11,9 @@ module Robodash
|
|
11
11
|
OPEN_TIMEOUT = 2
|
12
12
|
READ_TIMEOUT = 5
|
13
13
|
|
14
|
+
# Parse flexible format like "every 30 minutes", "3 days", "2 hours"
|
15
|
+
SCHEDULE_REGEX = /^(?:every\s+)?(\d+)\s*(minute|hour|day|week|month|year)s?$/
|
16
|
+
|
14
17
|
class << self
|
15
18
|
attr_accessor :api_token, :host, :enabled
|
16
19
|
|
@@ -26,13 +29,16 @@ module Robodash
|
|
26
29
|
# - weekly
|
27
30
|
# - monthly
|
28
31
|
# - yearly
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
})
|
32
|
+
#
|
33
|
+
# Examples:
|
34
|
+
# Robodash.ping("Some task", :daily, grace_period: 10.minutes)
|
35
|
+
# Robodash.ping("Some task", "every 10 minutes", grace_period: 10.minutes)
|
36
|
+
def ping(name, schedule = nil, grace_period: nil)
|
37
|
+
params = {name: name}
|
38
|
+
params.merge!({grace_period: grace_period.to_i}) if grace_period.present?
|
39
|
+
params.merge!(parse_schedule(schedule)) if schedule.present?
|
40
|
+
|
41
|
+
fire_and_forget("ping", params)
|
36
42
|
end
|
37
43
|
|
38
44
|
# Count should always be an integer
|
@@ -41,6 +47,27 @@ module Robodash
|
|
41
47
|
end
|
42
48
|
|
43
49
|
private
|
50
|
+
|
51
|
+
def parse_schedule(schedule)
|
52
|
+
schedule = schedule.to_s.strip.downcase
|
53
|
+
return predefined_schedules[schedule] if predefined_schedules[schedule]
|
54
|
+
|
55
|
+
match = schedule.match(SCHEDULE_REGEX)
|
56
|
+
return {schedule_number: match[1].to_i, schedule_period: match[2]} if match
|
57
|
+
|
58
|
+
{}
|
59
|
+
end
|
60
|
+
|
61
|
+
def predefined_schedules
|
62
|
+
{
|
63
|
+
"minutely" => {schedule_period: "minute", schedule_number: 1},
|
64
|
+
"hourly" => {schedule_period: "hour", schedule_number: 1},
|
65
|
+
"daily" => {schedule_period: "day", schedule_number: 1},
|
66
|
+
"weekly" => {schedule_period: "week", schedule_number: 1},
|
67
|
+
"monthly" => {schedule_period: "month", schedule_number: 1},
|
68
|
+
"yearly" => {schedule_period: "year", schedule_number: 1}
|
69
|
+
}
|
70
|
+
end
|
44
71
|
|
45
72
|
def fire_and_forget(endpoint, body)
|
46
73
|
return false unless enabled?
|