ocular 0.1.15 → 0.1.16
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/ocular/dsl/dsl.rb +1 -0
- data/lib/ocular/dsl/rabbitmq.rb +25 -0
- data/lib/ocular/dsl/runcontext.rb +1 -0
- data/lib/ocular/event/eventbase.rb +2 -5
- data/lib/ocular/event/eventfactory.rb +1 -0
- data/lib/ocular/inputs/cron_input.rb +45 -13
- data/lib/ocular/inputs/http_input.rb +10 -0
- data/lib/ocular/inputs/rabbitmq_input.rb +18 -15
- data/lib/ocular/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e7bdc14065534d11c655212e482f3e63f5fe1e3
|
4
|
+
data.tar.gz: 80bee22324973ce182d65d5c7518949e826bc1d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 839537f3335286e0269274211824b3dd8560f4857ec4a04789d43796ef2d71637ea99f74357d7cac72b91051e3eeb1e5f23a14d05332ba837d3da9efaf3f928e
|
7
|
+
data.tar.gz: 55a4b0fdf8c52dcf925740ef367061ceb372c59f677dfc06c1580506f5b18d07310fd2e4ff4d942c813aa1ccb9e162d99ed2676413d63132ece867b832fdf210
|
data/lib/ocular/dsl/dsl.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'etcd'
|
3
|
+
|
4
|
+
class Ocular
|
5
|
+
module DSL
|
6
|
+
module RabbitMQ
|
7
|
+
|
8
|
+
add_help "amqp", "Returns a channel to RabbitMQ broker"
|
9
|
+
|
10
|
+
def amqp()
|
11
|
+
datasources = ::Ocular::Settings::get(:datasources)
|
12
|
+
if !datasources or !datasources[:rabbitmq]
|
13
|
+
raise "No rabbitmq client settings"
|
14
|
+
end
|
15
|
+
settings = datasources[:rabbitmq] || {}
|
16
|
+
conn = Bunny.new(settings[:url] || nil)
|
17
|
+
conn.start
|
18
|
+
|
19
|
+
return conn.create_channel
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -12,7 +12,7 @@ class Ocular
|
|
12
12
|
attr_accessor :error
|
13
13
|
end
|
14
14
|
|
15
|
-
attr_accessor :proxy
|
15
|
+
attr_accessor :proxy, :last_run
|
16
16
|
|
17
17
|
def initialize(proxy, &block)
|
18
18
|
@callback = block
|
@@ -30,6 +30,7 @@ class Ocular
|
|
30
30
|
end
|
31
31
|
ensure
|
32
32
|
context.log_timing("execution_time", start)
|
33
|
+
@last_run = context
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
@@ -41,14 +42,12 @@ class Ocular
|
|
41
42
|
|
42
43
|
begin
|
43
44
|
r.response = __call(context, @callback)
|
44
|
-
#r.response = context.instance_eval(&@callback)
|
45
45
|
rescue Exception => error
|
46
46
|
r.error = error
|
47
47
|
end
|
48
48
|
|
49
49
|
Marshal.dump(r, writer)
|
50
50
|
writer.close
|
51
|
-
|
52
51
|
end
|
53
52
|
writer.close
|
54
53
|
|
@@ -57,7 +56,6 @@ class Ocular
|
|
57
56
|
reader.close
|
58
57
|
Process.wait(child_pid)
|
59
58
|
|
60
|
-
|
61
59
|
if r.error
|
62
60
|
raise r.error
|
63
61
|
end
|
@@ -66,7 +64,6 @@ class Ocular
|
|
66
64
|
|
67
65
|
def exec_nofork(context)
|
68
66
|
return __call(context, @callback)
|
69
|
-
#context.instance_eval(&@callback)
|
70
67
|
end
|
71
68
|
|
72
69
|
def __call(context, callback)
|
@@ -26,12 +26,27 @@ class Ocular
|
|
26
26
|
|
27
27
|
attr_reader :routes
|
28
28
|
attr_reader :scheduler
|
29
|
+
attr_reader :cron_enabled
|
29
30
|
|
30
31
|
def initialize(settings_factory)
|
31
|
-
settings = settings_factory[:
|
32
|
+
settings = settings_factory[:cron]
|
33
|
+
@cron_enabled = true
|
34
|
+
|
35
|
+
if settings[:lock]
|
36
|
+
@cron_enabled = false
|
37
|
+
end
|
32
38
|
|
33
39
|
@scheduler = ::Rufus::Scheduler.new
|
34
40
|
::Ocular.logger.debug "Starting Rufus cron scheduler"
|
41
|
+
|
42
|
+
if settings[:lock]
|
43
|
+
@scheduler.every(settings[:lock_delay] || "10s", :overlap => false) do
|
44
|
+
etcd = ::Ocular::DSL::Etcd.etcd()
|
45
|
+
|
46
|
+
ret = etcd.get(settings[:lock])
|
47
|
+
pp ret
|
48
|
+
end
|
49
|
+
end
|
35
50
|
end
|
36
51
|
|
37
52
|
def start()
|
@@ -42,6 +57,15 @@ class Ocular
|
|
42
57
|
@scheduler.shutdown
|
43
58
|
end
|
44
59
|
|
60
|
+
def disable()
|
61
|
+
@cron_enabled = false
|
62
|
+
end
|
63
|
+
|
64
|
+
def enable()
|
65
|
+
@cron_enabled = true
|
66
|
+
end
|
67
|
+
|
68
|
+
|
45
69
|
class DSLProxy
|
46
70
|
def initialize(proxy, handler, logger)
|
47
71
|
@proxy = proxy
|
@@ -54,9 +78,11 @@ class Ocular
|
|
54
78
|
::Ocular.logger.debug "Scheduling cron.in(#{rule}) for block #{block}"
|
55
79
|
|
56
80
|
id = @handler.scheduler.in(rule, :overlap => false) do
|
57
|
-
|
58
|
-
|
59
|
-
|
81
|
+
if @handler.cron_enabled
|
82
|
+
context = ::Ocular::DSL::RunContext.new(@logger)
|
83
|
+
context.log_cause("cron.in", {:rule => rule})
|
84
|
+
eventbase.exec(context)
|
85
|
+
end
|
60
86
|
end
|
61
87
|
|
62
88
|
@proxy.events[id] = eventbase
|
@@ -69,9 +95,11 @@ class Ocular
|
|
69
95
|
::Ocular.logger.debug "Scheduling cron.at(#{rule}) for block #{block}"
|
70
96
|
|
71
97
|
id = @handler.scheduler.at(rule, :overlap => false) do
|
72
|
-
|
73
|
-
|
74
|
-
|
98
|
+
if @handler.cron_enabled
|
99
|
+
context = ::Ocular::DSL::RunContext.new(@logger)
|
100
|
+
context.log_cause("cron.at", {:rule => rule})
|
101
|
+
eventbase.exec(context)
|
102
|
+
end
|
75
103
|
end
|
76
104
|
|
77
105
|
@proxy.events[id] = eventbase
|
@@ -84,9 +112,11 @@ class Ocular
|
|
84
112
|
::Ocular.logger.debug "Scheduling cron.every(#{rule}) for block #{block}"
|
85
113
|
|
86
114
|
id = @handler.scheduler.every(rule, :overlap => false) do
|
87
|
-
|
88
|
-
|
89
|
-
|
115
|
+
if @handler.cron_enabled
|
116
|
+
context = ::Ocular::DSL::RunContext.new(@logger)
|
117
|
+
context.log_cause("cron.every", {:rule => rule})
|
118
|
+
eventbase.exec(context)
|
119
|
+
end
|
90
120
|
end
|
91
121
|
|
92
122
|
@proxy.events[id] = eventbase
|
@@ -99,9 +129,11 @@ class Ocular
|
|
99
129
|
::Ocular.logger.debug "Scheduling cron.cron(#{rule}) for block #{block}"
|
100
130
|
|
101
131
|
id = @handler.scheduler.cron(rule, :overlap => false) do
|
102
|
-
|
103
|
-
|
104
|
-
|
132
|
+
if @handler.cron_enabled
|
133
|
+
context = ::Ocular::DSL::RunContext.new(@logger)
|
134
|
+
context.log_cause("cron.cron", {:rule => rule})
|
135
|
+
eventbase.exec(context)
|
136
|
+
end
|
105
137
|
end
|
106
138
|
|
107
139
|
@proxy.events[id] = eventbase
|
@@ -595,6 +595,16 @@ class Ocular
|
|
595
595
|
@stopsignal.pop
|
596
596
|
server.stop(true)
|
597
597
|
end
|
598
|
+
|
599
|
+
define_check_route()
|
600
|
+
end
|
601
|
+
|
602
|
+
def define_check_route
|
603
|
+
pattern, keys = compile("/check")
|
604
|
+
|
605
|
+
(@routes["GET"] ||= []) << build_signature(pattern, keys) do |context|
|
606
|
+
[200, "OK"]
|
607
|
+
end
|
598
608
|
end
|
599
609
|
|
600
610
|
def stop()
|
@@ -2,7 +2,7 @@
|
|
2
2
|
require 'ocular/inputs/base.rb'
|
3
3
|
require 'ocular/dsl/dsl.rb'
|
4
4
|
require 'ocular/dsl/runcontext.rb'
|
5
|
-
require '
|
5
|
+
require 'bunny'
|
6
6
|
|
7
7
|
class Ocular
|
8
8
|
module Inputs
|
@@ -23,19 +23,15 @@ class Ocular
|
|
23
23
|
|
24
24
|
attr_reader :routes
|
25
25
|
attr_reader :conn
|
26
|
+
attr_reader :settings
|
26
27
|
|
27
28
|
def initialize(settings_factory)
|
28
|
-
settings = settings_factory[:rabbitmq]
|
29
|
+
@settings = settings_factory[:rabbitmq]
|
29
30
|
|
30
31
|
::Ocular.logger.debug "Starting RabbitMQ input"
|
31
32
|
|
32
33
|
@conn = Bunny.new
|
33
|
-
conn.start
|
34
|
-
|
35
|
-
ch = conn.create_channel
|
36
|
-
q = ch.queue("bunny.examples.hello_world", :auto_delete => true)
|
37
|
-
x = ch.default_exchange
|
38
|
-
|
34
|
+
@conn.start
|
39
35
|
end
|
40
36
|
|
41
37
|
def start()
|
@@ -43,14 +39,14 @@ class Ocular
|
|
43
39
|
end
|
44
40
|
|
45
41
|
def stop()
|
46
|
-
@
|
42
|
+
@conn.close
|
47
43
|
end
|
48
44
|
|
49
45
|
class RabbitMQRunContext < ::Ocular::DSL::RunContext
|
50
46
|
attr_accessor :delivery_info, :metadata, :payload
|
51
47
|
|
52
|
-
def initialize()
|
53
|
-
super(
|
48
|
+
def initialize(logger)
|
49
|
+
super(logger)
|
54
50
|
end
|
55
51
|
end
|
56
52
|
|
@@ -62,23 +58,30 @@ class Ocular
|
|
62
58
|
@logger = logger
|
63
59
|
end
|
64
60
|
|
65
|
-
def subscribe(
|
61
|
+
def subscribe(queue, *settings, &block)
|
66
62
|
eventbase = Ocular::DSL::EventBase.new(@proxy, &block)
|
67
|
-
::Ocular.logger.debug "rabbitmq.subscribe to# #{
|
63
|
+
::Ocular.logger.debug "rabbitmq.subscribe to# #{queue} for block #{block}"
|
64
|
+
|
65
|
+
ch = @handler.conn.create_channel
|
66
|
+
q = ch.queue(queue, *settings)
|
68
67
|
|
69
|
-
q.subscribe(
|
68
|
+
q.subscribe(:manual_ack => true) do |delivery_info, metadata, payload|
|
70
69
|
context = RabbitMQRunContext.new(@logger)
|
71
|
-
context.log_cause("rabbitmq.subscribe(#{
|
70
|
+
context.log_cause("rabbitmq.subscribe(#{queue})", {:delivery_info => delivery_info, :metadata => metadata, :payload => payload})
|
72
71
|
context.delivery_info = delivery_info
|
73
72
|
context.metadata = metadata
|
74
73
|
context.payload = payload
|
75
74
|
eventbase.exec(context)
|
75
|
+
ch.acknowledge(delivery_info.delivery_tag, false)
|
76
76
|
end
|
77
77
|
|
78
|
+
id = queue + "-" + block.to_s
|
79
|
+
|
78
80
|
@proxy.events[id] = eventbase
|
79
81
|
|
80
82
|
return id
|
81
83
|
end
|
84
|
+
|
82
85
|
end
|
83
86
|
|
84
87
|
end
|
data/lib/ocular/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juho Mäkinen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rye
|
@@ -204,6 +204,7 @@ files:
|
|
204
204
|
- lib/ocular/dsl/logging.rb
|
205
205
|
- lib/ocular/dsl/mysql.rb
|
206
206
|
- lib/ocular/dsl/orbit.rb
|
207
|
+
- lib/ocular/dsl/rabbitmq.rb
|
207
208
|
- lib/ocular/dsl/runcontext.rb
|
208
209
|
- lib/ocular/dsl/ssh.rb
|
209
210
|
- lib/ocular/event/eventbase.rb
|