delayed_job_monitor 0.0.2 → 0.0.4
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.
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
require 'sinatra'
|
|
2
1
|
require 'sinatra/base'
|
|
2
|
+
require 'active_support'
|
|
3
|
+
require 'active_record'
|
|
4
|
+
require 'delayed_job'
|
|
3
5
|
require 'haml'
|
|
4
6
|
|
|
5
7
|
module DelayedJobMonitor
|
|
@@ -13,9 +15,12 @@ module DelayedJobMonitor
|
|
|
13
15
|
|
|
14
16
|
def delayed_job
|
|
15
17
|
begin
|
|
16
|
-
DelayedJobMonitor
|
|
18
|
+
if DelayedJobMonitor.connected?
|
|
19
|
+
DelayedJobMonitor::Job
|
|
20
|
+
else
|
|
21
|
+
nil
|
|
22
|
+
end
|
|
17
23
|
rescue
|
|
18
|
-
false
|
|
19
24
|
end
|
|
20
25
|
end
|
|
21
26
|
|
|
@@ -1,31 +1,5 @@
|
|
|
1
|
-
#delayed_job_monitor.establish_connection
|
|
2
|
-
|
|
3
1
|
module DelayedJobMonitor
|
|
4
2
|
class Job < ActiveRecord::Base
|
|
5
3
|
self.table_name = "delayed_jobs"
|
|
6
|
-
|
|
7
|
-
def self.queues
|
|
8
|
-
@queues = delayed_job_monitor::Job.select(:queue).map(&:queue).compact.uniq.sort
|
|
9
|
-
return @queues
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def host
|
|
13
|
-
unless DelayedJobMonitor[:database]["host"].blank?
|
|
14
|
-
return DelayedJobMonitor[:database]["host"]
|
|
15
|
-
else
|
|
16
|
-
return "localhost"
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def description
|
|
21
|
-
details = {}
|
|
22
|
-
parsed_handler = self.handler.split(/\n/)
|
|
23
|
-
parsed_handler.map{|x| details[x.split(":")[0].strip.split(/\//).last] = x.split(/\:|\/|\s/).last.strip unless x.blank?}
|
|
24
|
-
target_class = details["ActiveRecord"]
|
|
25
|
-
target_id = details["id"].to_s.gsub(/\W/,"").to_i if details["id"].present?
|
|
26
|
-
performable_class = details["object"] if details["object"].present?
|
|
27
|
-
performable_method = details["method_name"] if details["method_name"].present?
|
|
28
|
-
return "Perform #{performable_class}:#{performable_method} on #{target_class}##{target_id}"
|
|
29
|
-
end
|
|
30
4
|
end
|
|
31
5
|
end
|
|
@@ -6,6 +6,7 @@ module DelayedJobMonitor
|
|
|
6
6
|
@@instance_collector = []
|
|
7
7
|
def initialize(name="default",host="localhost",rails_path=nil,username=nil,password=nil)
|
|
8
8
|
unless host == "localhost"
|
|
9
|
+
p host
|
|
9
10
|
@connection = Net::SSH.start(host,username,:password=>password)
|
|
10
11
|
@username = username
|
|
11
12
|
else
|
data/lib/delayed_job_monitor.rb
CHANGED
|
@@ -20,7 +20,7 @@ module DelayedJobMonitor
|
|
|
20
20
|
def self.establish_connection
|
|
21
21
|
begin
|
|
22
22
|
if DelayedJobMonitor[:database]["host"].nil?
|
|
23
|
-
|
|
23
|
+
p "No database connection defined in config.yml"
|
|
24
24
|
else
|
|
25
25
|
if defined? connection
|
|
26
26
|
p "There is already a DB connection locally...closing"
|
|
@@ -34,7 +34,7 @@ module DelayedJobMonitor
|
|
|
34
34
|
return connection
|
|
35
35
|
end
|
|
36
36
|
rescue
|
|
37
|
-
raise
|
|
37
|
+
raise true
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
@@ -47,22 +47,40 @@ module DelayedJobMonitor
|
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
+
def self.connected?
|
|
51
|
+
if defined? DelayedJobMonitor.connection
|
|
52
|
+
return true
|
|
53
|
+
else
|
|
54
|
+
return false
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
50
58
|
def self.stand_alone_mode?
|
|
51
59
|
!ENV["RAILS_ENV"].present?
|
|
52
60
|
end
|
|
53
61
|
|
|
54
62
|
def self.initialize_servers
|
|
55
|
-
DelayedJobMonitor[:hosts].
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
unless DelayedJobMonitor[:hosts].first["host"].nil?
|
|
64
|
+
|
|
65
|
+
DelayedJobMonitor[:hosts].each do |host|
|
|
66
|
+
DelayedJobMonitor::Server.new(host["name"],host["host"],host["rails_path"],host["username"],host["password"])
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
if delayed_job_running_locally?
|
|
70
|
+
DelayedJobMonitor::Server.new
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
return DelayedJobMonitor::Server.servers
|
|
74
|
+
else
|
|
59
75
|
DelayedJobMonitor::Server.new
|
|
76
|
+
p "No hosts configured. Connecting to localhost"
|
|
60
77
|
end
|
|
61
|
-
return DelayedJobMonitor::Server.servers
|
|
62
78
|
end
|
|
63
79
|
|
|
64
80
|
def self.start!
|
|
65
|
-
|
|
81
|
+
if stand_alone_mode? && !connected?
|
|
82
|
+
DelayedJobMonitor.establish_connection
|
|
83
|
+
end
|
|
66
84
|
DelayedJobMonitor.initialize_servers
|
|
67
85
|
DelayedJobMonitor::App.run!
|
|
68
86
|
end
|
|
@@ -79,6 +97,4 @@ if DelayedJobMonitor.stand_alone_mode?
|
|
|
79
97
|
return nil
|
|
80
98
|
end
|
|
81
99
|
end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
DelayedJobMonitor.establish_connection
|
|
100
|
+
end
|