gnomon 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gnomon.rb +38 -0
- data/lib/gnomon/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b469cb0fddada2cb893d4139ce126ea9e5aa143d
|
4
|
+
data.tar.gz: e697d7b0d9f83b3dd2bdee5f40739f7e681428fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c9070fff89e68b8fa340e9857caf08ffdab3516bb53a108a4c06be4484c77b02e1bd24e5a2e85be27967e9a5f591a88463df8f23b0b195c3266d21db461e782
|
7
|
+
data.tar.gz: 962f27e6d37f823e187d767dc533f64a5474582269745bc3508f947dc799ea06525b19463417e66d6afc1fef54888fe4d88b8e6616ffee1330491643612ea778
|
data/lib/gnomon.rb
CHANGED
@@ -20,6 +20,8 @@ class Gnomon
|
|
20
20
|
DEFAULT_GRANULARITY = 1
|
21
21
|
|
22
22
|
# Construct
|
23
|
+
# Creates a new Gnomon instance
|
24
|
+
# @param [Float] granularity The desired resolution of the event queue, in seconds
|
23
25
|
def initialize granularity = DEFAULT_GRANULARITY
|
24
26
|
|
25
27
|
# Set Granularity
|
@@ -36,6 +38,13 @@ class Gnomon
|
|
36
38
|
end
|
37
39
|
|
38
40
|
# Schedule Event
|
41
|
+
# Schedules a generic event
|
42
|
+
# @param [Object] id An ID for later de-scheduling of this event
|
43
|
+
# @param [Symbol] mode The mode of scheduling - can be any of [ :at, :in, :every ]
|
44
|
+
# @param [Hash] mode_options Mode-specific options hash - See documentation for desired mode
|
45
|
+
# @param [Object] timespec Mode-specific time-specification for 'when' to trigger the event
|
46
|
+
# @param [Object] args Arguments to be passed as-is to the event's block upon execution
|
47
|
+
# @param [Object] block A block to be executed upon event trigger
|
39
48
|
def schedule id, mode, mode_options, timespec, *args, &block
|
40
49
|
|
41
50
|
# Synchronize
|
@@ -60,21 +69,40 @@ class Gnomon
|
|
60
69
|
end
|
61
70
|
|
62
71
|
# Schedule Event at a given date/time
|
72
|
+
# Shortcut to schedule an event to be triggered once at a specific date/time
|
73
|
+
# @param [Object] id
|
74
|
+
# @param [String] date_time A date / time string
|
75
|
+
# @param [Object] args
|
76
|
+
# @param [Object] block
|
63
77
|
def schedule_at id, date_time, *args, &block
|
64
78
|
schedule id, :at, {}, date_time, *args, &block
|
65
79
|
end
|
66
80
|
|
67
81
|
# Schedule Event in a given number of seconds
|
82
|
+
# Shortcut to schedule an event to be triggered once after a given amount of time
|
83
|
+
# @param [Object] id
|
84
|
+
# @param [Float] time
|
85
|
+
# @param [Object] args
|
86
|
+
# @param [Object] block
|
68
87
|
def schedule_in id, time, *args, &block
|
69
88
|
schedule id, :in, {}, time, *args, &block
|
70
89
|
end
|
71
90
|
|
72
91
|
# Schedule Event at a given interval (seconds)
|
92
|
+
# Shortcut to schedule an event to be triggered periodically at a given time interval
|
93
|
+
# @param [Object] id
|
94
|
+
# @param [Float] interval
|
95
|
+
# @param [boolean] async When true, schedule the next trigger before actually running the event's block - otherwise, schedule the next trigger only once the event block completes
|
96
|
+
# @param [Object] args
|
97
|
+
# @param [Object] block
|
73
98
|
def schedule_every id, interval, async, *args, &block
|
74
99
|
schedule id, :every, { async: async }, interval, *args, &block
|
75
100
|
end
|
76
101
|
|
77
102
|
# De-schedule
|
103
|
+
# Removes one or more previously-scheduled events from the scheduler
|
104
|
+
# @param [Object] id The ID of the event(s) to remove (all events with this ID will be removed)
|
105
|
+
# @param [Object] keep_running When true, the next trigger is maintained
|
78
106
|
def deschedule id, keep_running = false
|
79
107
|
|
80
108
|
# Synchronize
|
@@ -93,6 +121,8 @@ class Gnomon
|
|
93
121
|
private
|
94
122
|
|
95
123
|
# Enqueue Next Run
|
124
|
+
# Registers the next run for a given event into the event queue
|
125
|
+
# @param [Hash] event
|
96
126
|
def enqueue_next_run event
|
97
127
|
next_run = next_run event[:mode], event[:ts]
|
98
128
|
pos = @equeue.index { |p| p[:next_run] >= next_run } || 0
|
@@ -100,6 +130,10 @@ class Gnomon
|
|
100
130
|
end
|
101
131
|
|
102
132
|
# Determine Next Run
|
133
|
+
# Determines when to trigger the next run for a given event
|
134
|
+
# @param [Symbol] mode
|
135
|
+
# @param [Object] ts
|
136
|
+
# @return [Float] A floating-point timestamp representing the time at which to trigger the next run
|
103
137
|
def next_run mode, ts
|
104
138
|
case mode
|
105
139
|
when :at
|
@@ -112,11 +146,13 @@ class Gnomon
|
|
112
146
|
end
|
113
147
|
|
114
148
|
# Run
|
149
|
+
# Main Loop
|
115
150
|
def run
|
116
151
|
update until @stop
|
117
152
|
end
|
118
153
|
|
119
154
|
# Update
|
155
|
+
# Update Gnomon's internal states
|
120
156
|
def update
|
121
157
|
|
122
158
|
# Synchronize { Trigger Next Event in Queue }
|
@@ -127,6 +163,8 @@ class Gnomon
|
|
127
163
|
end
|
128
164
|
|
129
165
|
# Trigger Event
|
166
|
+
# Triggers an event, executing its block and re-scheduling the next run when appropriate
|
167
|
+
# @param [Hash] event
|
130
168
|
def trigger event
|
131
169
|
|
132
170
|
# Spawn Thread around Event's Block
|
data/lib/gnomon/version.rb
CHANGED