ocular 0.1.7 → 0.1.8
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/bin/ocular +10 -3
- data/lib/ocular/dsl/dsl.rb +6 -0
- data/lib/ocular/dsl/orbit.rb +10 -5
- data/lib/ocular/dsl/runcontext.rb +17 -1
- data/lib/ocular/event/eventfactory.rb +2 -0
- data/lib/ocular/inputs/cron_input.rb +111 -0
- data/lib/ocular/ocular.rb +1 -0
- data/lib/ocular/version.rb +1 -1
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9744f295fb350d3864ab65a80a3506281f776f3
|
4
|
+
data.tar.gz: 453713667fc0c6c7eec8b359dbab2b49d4523b25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4efd125317945bc07ae03513116e087884895988bfa2d2d92f61326aa9da7d2d9f1d0418b18f005c6c25f5e779c0bd6ebda18c0281b86c5e9ea8a17518bfcbe
|
7
|
+
data.tar.gz: 456e9158a506e24382c8a1fa03c6d17ab87ea2fa2b0a8afe11689c7170ab9b267724dff8a1b823506d89d08f3d6c9b6a0c10b07b4e601aa3dd8a0d453ea91210
|
data/bin/ocular
CHANGED
@@ -114,13 +114,18 @@ else
|
|
114
114
|
if ARGV.length == 0
|
115
115
|
puts "Missing script file to run, starting ocular interactive shell. use \"ocular -h\" to get full options"
|
116
116
|
puts ""
|
117
|
-
longest_name = $dsl_help.keys.max_by(&:length).length
|
117
|
+
longest_name = [$dsl_help.keys.max_by(&:length).length, $dsl_event_help.keys.max_by(&:length).length].max
|
118
118
|
$dsl_help.each do |cmd, help|
|
119
119
|
spacing = " "*(longest_name.to_i+1-cmd.length)
|
120
120
|
puts " #{cmd}#{spacing}#{help}"
|
121
121
|
end
|
122
122
|
puts ""
|
123
|
-
|
123
|
+
puts "Event triggering functions:"
|
124
|
+
$dsl_event_help.each do |cmd, help|
|
125
|
+
spacing = " "*(longest_name.to_i+1-cmd.length)
|
126
|
+
puts " #{cmd}#{spacing}#{help}"
|
127
|
+
end
|
128
|
+
puts ""
|
124
129
|
ARGV.clear
|
125
130
|
require 'irb'
|
126
131
|
IRB.setup nil
|
@@ -144,7 +149,9 @@ else
|
|
144
149
|
IRB.conf[:SAVE_HISTORY] = 1000
|
145
150
|
IRB.conf[:HISTORY_FILE] = '~/.ocular_history'
|
146
151
|
|
147
|
-
|
152
|
+
ef = Ocular::Event::EventFactory.new
|
153
|
+
|
154
|
+
context = Ocular::DSL::REPLRunContext.new(ef.handlers)
|
148
155
|
|
149
156
|
irb = IRB::Irb.new(IRB::WorkSpace.new(context))
|
150
157
|
IRB.conf[:MAIN_CONTEXT] = irb.context
|
data/lib/ocular/dsl/dsl.rb
CHANGED
data/lib/ocular/dsl/orbit.rb
CHANGED
@@ -12,13 +12,18 @@ class Ocular
|
|
12
12
|
@etcd = etcd
|
13
13
|
end
|
14
14
|
|
15
|
-
add_help "orbit
|
15
|
+
add_help "orbit.get_service_endpoints(service_name)", "Returns an array of ips running service_name"
|
16
16
|
def get_service_endpoints(service_name)
|
17
17
|
orbit_endpoints = []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
begin
|
19
|
+
endpoints = @etcd.get("/orbit/services/#{service_name}/endpoints").node.children
|
20
|
+
pp endpoints
|
21
|
+
endpoints.each do |node|
|
22
|
+
ip = node.key.match(/.*endpoints.(.+?):.+/).captures[0]
|
23
|
+
orbit_endpoints << ip
|
24
|
+
end
|
25
|
+
rescue ::Etcd::KeyNotFound
|
26
|
+
return []
|
22
27
|
end
|
23
28
|
|
24
29
|
return orbit_endpoints
|
@@ -1,5 +1,6 @@
|
|
1
1
|
|
2
2
|
require 'securerandom'
|
3
|
+
require 'ocular/inputs/cron_input'
|
3
4
|
|
4
5
|
class Ocular
|
5
6
|
module DSL
|
@@ -15,6 +16,8 @@ class Ocular
|
|
15
16
|
include Ocular::DSL::Etcd
|
16
17
|
include Ocular::DSL::Orbit
|
17
18
|
|
19
|
+
include Ocular::Inputs::Cron::DSL
|
20
|
+
|
18
21
|
def initialize
|
19
22
|
@run_id = SecureRandom.uuid()
|
20
23
|
@logger = Ocular::DSL::Logger.new
|
@@ -25,7 +28,7 @@ class Ocular
|
|
25
28
|
if self.proxy
|
26
29
|
self.proxy.send(method_sym, *arguments, &block)
|
27
30
|
else
|
28
|
-
raise NoMethodError
|
31
|
+
raise NoMethodError, "undefined method `#{method_sym}` in event #{self.class_name}"
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
@@ -39,5 +42,18 @@ class Ocular
|
|
39
42
|
end
|
40
43
|
end
|
41
44
|
end
|
45
|
+
|
46
|
+
class REPLRunContext < RunContext
|
47
|
+
attr_reader :handlers
|
48
|
+
attr_reader :events
|
49
|
+
attr_reader :do_fork
|
50
|
+
|
51
|
+
def initialize(handlers)
|
52
|
+
super()
|
53
|
+
@events = {}
|
54
|
+
@handlers = handlers
|
55
|
+
@do_fork = false
|
56
|
+
end
|
57
|
+
end
|
42
58
|
end
|
43
59
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'ocular/inputs/handlers.rb'
|
2
2
|
require 'ocular/event/eventbase.rb'
|
3
3
|
require 'ocular/inputs/http_input.rb'
|
4
|
+
require 'ocular/inputs/cron_input.rb'
|
4
5
|
|
5
6
|
class Ocular
|
6
7
|
module Event
|
@@ -24,6 +25,7 @@ class Ocular
|
|
24
25
|
include Ocular::DSL::Etcd
|
25
26
|
|
26
27
|
include Ocular::Inputs::HTTP::DSL
|
28
|
+
include Ocular::Inputs::Cron::DSL
|
27
29
|
|
28
30
|
def fork(value)
|
29
31
|
@do_fork = value
|
@@ -0,0 +1,111 @@
|
|
1
|
+
|
2
|
+
require 'ocular/inputs/base.rb'
|
3
|
+
require 'ocular/dsl/dsl.rb'
|
4
|
+
require 'ocular/dsl/runcontext.rb'
|
5
|
+
require 'rufus/scheduler'
|
6
|
+
|
7
|
+
class Ocular
|
8
|
+
module Inputs
|
9
|
+
|
10
|
+
module Cron
|
11
|
+
|
12
|
+
module DSL
|
13
|
+
|
14
|
+
add_event_help "cron.in(rule)", "Schedule event to be executed in 'rule'. eg: '1m'"
|
15
|
+
add_event_help "cron.at(rule)", "Schedule event to be executed at 'rule'. eg: '2030/12/12 23:30:00'"
|
16
|
+
add_event_help "cron.every(rule)", "Schedule event to be executed every 'rule'. eg: '15m'"
|
17
|
+
add_event_help "cron.cron(rule)", "Schedule event with cron syntax. eg: '5 0 * * *'"
|
18
|
+
def cron()
|
19
|
+
handler = handlers.get(::Ocular::Inputs::Cron::Input)
|
20
|
+
return Input::DSLProxy.new(self, handler)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
class Input < ::Ocular::Inputs::Base
|
26
|
+
|
27
|
+
attr_reader :routes
|
28
|
+
attr_reader :scheduler
|
29
|
+
|
30
|
+
def initialize(settings_factory)
|
31
|
+
settings = settings_factory[:http]
|
32
|
+
|
33
|
+
@scheduler = ::Rufus::Scheduler.new
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def start()
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def stop()
|
42
|
+
@scheduler.shutdown
|
43
|
+
end
|
44
|
+
|
45
|
+
class DSLProxy
|
46
|
+
def initialize(proxy, handler)
|
47
|
+
@proxy = proxy
|
48
|
+
@handler = handler
|
49
|
+
end
|
50
|
+
|
51
|
+
def in(rule, &block)
|
52
|
+
eventbase = Ocular::DSL::EventBase.new(&block)
|
53
|
+
eventbase.proxy = @proxy
|
54
|
+
|
55
|
+
id = @handler.scheduler.in(rule) do
|
56
|
+
context = ::Ocular::DSL::RunContext.new
|
57
|
+
eventbase.exec(context)
|
58
|
+
end
|
59
|
+
|
60
|
+
@proxy.events[id] = eventbase
|
61
|
+
|
62
|
+
return id
|
63
|
+
end
|
64
|
+
|
65
|
+
def at(rule, &block)
|
66
|
+
eventbase = Ocular::DSL::EventBase.new(&block)
|
67
|
+
eventbase.proxy = @proxy
|
68
|
+
|
69
|
+
id = @handler.scheduler.at(rule) do
|
70
|
+
context = ::Ocular::DSL::RunContext.new
|
71
|
+
eventbase.exec(context)
|
72
|
+
end
|
73
|
+
|
74
|
+
@proxy.events[id] = eventbase
|
75
|
+
|
76
|
+
return id
|
77
|
+
end
|
78
|
+
|
79
|
+
def every(rule, &block)
|
80
|
+
eventbase = Ocular::DSL::EventBase.new(&block)
|
81
|
+
eventbase.proxy = @proxy
|
82
|
+
|
83
|
+
id = @handler.scheduler.every(rule) do
|
84
|
+
context = ::Ocular::DSL::RunContext.new
|
85
|
+
eventbase.exec(context)
|
86
|
+
end
|
87
|
+
|
88
|
+
@proxy.events[id] = eventbase
|
89
|
+
|
90
|
+
return id
|
91
|
+
end
|
92
|
+
|
93
|
+
def cron(rule, &block)
|
94
|
+
eventbase = Ocular::DSL::EventBase.new(&block)
|
95
|
+
eventbase.proxy = @proxy
|
96
|
+
|
97
|
+
id = @handler.scheduler.cron(rule) do
|
98
|
+
context = ::Ocular::DSL::RunContext.new
|
99
|
+
eventbase.exec(context)
|
100
|
+
end
|
101
|
+
|
102
|
+
@proxy.events[id] = eventbase
|
103
|
+
|
104
|
+
return id
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/lib/ocular/ocular.rb
CHANGED
data/lib/ocular/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ocular
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juho Mäkinen
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - '='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 0.3.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rufus-scheduler
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 3.2.0
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 3.2.0
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: rspec
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -152,6 +166,7 @@ files:
|
|
152
166
|
- lib/ocular/event/eventbase.rb
|
153
167
|
- lib/ocular/event/eventfactory.rb
|
154
168
|
- lib/ocular/inputs/base.rb
|
169
|
+
- lib/ocular/inputs/cron_input.rb
|
155
170
|
- lib/ocular/inputs/handlers.rb
|
156
171
|
- lib/ocular/inputs/http_input.rb
|
157
172
|
- lib/ocular/mixin/from_file.rb
|