minicron 0.1.1 → 0.2
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/README.md +96 -43
- data/Rakefile +9 -1
- data/lib/minicron.rb +9 -4
- data/lib/minicron/alert.rb +2 -1
- data/lib/minicron/alert/email.rb +7 -2
- data/lib/minicron/alert/pagerduty.rb +3 -2
- data/lib/minicron/alert/sms.rb +2 -1
- data/lib/minicron/cli.rb +49 -19
- data/lib/minicron/constants.rb +2 -1
- data/lib/minicron/cron.rb +6 -6
- data/lib/minicron/hub/app.rb +8 -8
- data/lib/minicron/hub/assets/app/controllers/executions.js +4 -3
- data/lib/minicron/hub/assets/app/controllers/hosts.js +4 -4
- data/lib/minicron/hub/assets/app/controllers/jobs.js +4 -4
- data/lib/minicron/hub/assets/app/controllers/schedules.js +4 -1
- data/lib/minicron/hub/controllers/api/executions.rb +4 -4
- data/lib/minicron/hub/controllers/api/hosts.rb +18 -5
- data/lib/minicron/hub/controllers/api/job_execution_outputs.rb +2 -2
- data/lib/minicron/hub/controllers/api/jobs.rb +8 -8
- data/lib/minicron/hub/controllers/api/schedule.rb +10 -10
- data/lib/minicron/hub/db/schema.rb +70 -65
- data/lib/minicron/hub/db/schema.sql +53 -25
- data/lib/minicron/hub/models/execution.rb +1 -1
- data/lib/minicron/hub/models/host.rb +10 -1
- data/lib/minicron/hub/models/job.rb +3 -3
- data/lib/minicron/hub/models/schedule.rb +1 -1
- data/lib/minicron/hub/serializers/execution.rb +61 -57
- data/lib/minicron/hub/serializers/host.rb +49 -42
- data/lib/minicron/hub/serializers/job.rb +82 -78
- data/lib/minicron/hub/serializers/job_execution_output.rb +42 -38
- data/lib/minicron/hub/serializers/schedule.rb +56 -52
- data/lib/minicron/hub/views/handlebars/executions.erb +7 -1
- data/lib/minicron/hub/views/handlebars/hosts.erb +2 -2
- data/lib/minicron/hub/views/handlebars/schedules.erb +3 -3
- data/lib/minicron/monitor.rb +4 -4
- data/lib/minicron/transport/client.rb +6 -6
- data/lib/minicron/transport/faye/client.rb +4 -4
- data/lib/minicron/transport/faye/extensions/job_handler.rb +3 -2
- data/lib/minicron/transport/faye/server.rb +1 -0
- data/lib/minicron/transport/server.rb +2 -2
- data/lib/minicron/transport/ssh.rb +6 -8
- data/spec/minicron/cli_spec.rb +4 -4
- data/spec/minicron/transport/client_spec.rb +2 -2
- data/spec/minicron/transport/faye/client_spec.rb +7 -7
- data/spec/minicron/transport/server_spec.rb +1 -1
- data/spec/minicron_spec.rb +2 -1
- data/spec/valid_config.toml +1 -0
- metadata +16 -2
data/lib/minicron/monitor.rb
CHANGED
@@ -17,15 +17,15 @@ module Minicron
|
|
17
17
|
case Minicron.config['database']['type']
|
18
18
|
when 'mysql'
|
19
19
|
# Establish a database connection
|
20
|
-
ActiveRecord::Base.establish_connection(
|
20
|
+
ActiveRecord::Base.establish_connection(
|
21
21
|
:adapter => 'mysql2',
|
22
22
|
:host => Minicron.config['database']['host'],
|
23
23
|
:database => Minicron.config['database']['database'],
|
24
24
|
:username => Minicron.config['database']['username'],
|
25
25
|
:password => Minicron.config['database']['password']
|
26
|
-
|
26
|
+
)
|
27
27
|
else
|
28
|
-
|
28
|
+
fail Exception, "The database #{Minicron.config['database']['type']} is not supported"
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -44,7 +44,7 @@ module Minicron
|
|
44
44
|
sleep 60
|
45
45
|
|
46
46
|
# While the monitor is active run it in a loop ~every minute
|
47
|
-
while @active
|
47
|
+
while @active
|
48
48
|
# Get all the schedules
|
49
49
|
schedules = Minicron::Hub::Schedule.all
|
50
50
|
|
@@ -24,12 +24,12 @@ module Minicron
|
|
24
24
|
# @return [Hash]
|
25
25
|
def setup(job_hash, command, fqdn, hostname)
|
26
26
|
# Send a request to set up the job
|
27
|
-
publish("/job/#{job_hash}/status",
|
27
|
+
publish("/job/#{job_hash}/status",
|
28
28
|
:action => 'SETUP',
|
29
29
|
:command => command,
|
30
30
|
:fqdn => fqdn,
|
31
31
|
:hostname => hostname
|
32
|
-
|
32
|
+
)
|
33
33
|
|
34
34
|
# Wait for the response..
|
35
35
|
ensure_delivery
|
@@ -64,16 +64,16 @@ module Minicron
|
|
64
64
|
# @param message [String]
|
65
65
|
def publish(channel, message)
|
66
66
|
# Set up the data to send to faye
|
67
|
-
data = {:channel => channel, :data => {
|
68
|
-
:ts => Time.now.utc.strftime(
|
67
|
+
data = { :channel => channel, :data => {
|
68
|
+
:ts => Time.now.utc.strftime('%Y-%m-%d %H:%M:%S'),
|
69
69
|
:message => message,
|
70
70
|
:seq => @seq
|
71
|
-
}}
|
71
|
+
} }
|
72
72
|
|
73
73
|
# Increment the sequence id
|
74
74
|
@seq += 1
|
75
75
|
|
76
|
-
request(
|
76
|
+
request(:message => data.to_json)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -58,22 +58,22 @@ module Minicron
|
|
58
58
|
|
59
59
|
# Did the request succeed? If so remove it from the queue
|
60
60
|
req.callback do
|
61
|
-
@responses.push(
|
61
|
+
@responses.push(
|
62
62
|
:status => req.response_header.status,
|
63
63
|
:header => req.response_header,
|
64
64
|
:body => req.response
|
65
|
-
|
65
|
+
)
|
66
66
|
|
67
67
|
queue.delete(req_id)
|
68
68
|
end
|
69
69
|
|
70
70
|
# If not retry the request up to @retries times
|
71
71
|
req.errback do |error|
|
72
|
-
@responses.push(
|
72
|
+
@responses.push(
|
73
73
|
:status => req.response_header.status,
|
74
74
|
:header => req.response_header,
|
75
75
|
:body => req.response
|
76
|
-
|
76
|
+
)
|
77
77
|
|
78
78
|
if @retry_counts[req_id] < @retries
|
79
79
|
@retry_counts[req_id] += 1
|
@@ -66,11 +66,12 @@ module Minicron
|
|
66
66
|
host = Minicron::Hub::Host.where(:fqdn => data['fqdn']).first
|
67
67
|
|
68
68
|
# Create it if it didn't exist!
|
69
|
-
if
|
69
|
+
if !host
|
70
70
|
host = Minicron::Hub::Host.create(
|
71
71
|
:name => data['hostname'],
|
72
72
|
:fqdn => data['fqdn'],
|
73
|
-
:host => request.ip
|
73
|
+
:host => request.ip,
|
74
|
+
:port => 22
|
74
75
|
)
|
75
76
|
|
76
77
|
# Generate a new SSH key - TODO: add passphrase
|
@@ -44,7 +44,7 @@ module Minicron
|
|
44
44
|
# Stops the thin server if it's running
|
45
45
|
# @return [Boolean] whether the server was stopped or not
|
46
46
|
def stop!
|
47
|
-
return false unless running? && server
|
47
|
+
return false unless running? && !server.nil?
|
48
48
|
|
49
49
|
server.stop
|
50
50
|
true
|
@@ -53,7 +53,7 @@ module Minicron
|
|
53
53
|
# Returns a bool based on whether
|
54
54
|
# @return [Boolean]
|
55
55
|
def running?
|
56
|
-
return false unless server
|
56
|
+
return false unless !server.nil?
|
57
57
|
|
58
58
|
server.running?
|
59
59
|
end
|
@@ -14,7 +14,7 @@ module Minicron
|
|
14
14
|
@private_key = File.expand_path(options[:private_key])
|
15
15
|
|
16
16
|
# TODO: Make these configurable?
|
17
|
-
@user =
|
17
|
+
@user = 'root'
|
18
18
|
@auth_methods = ['publickey']
|
19
19
|
@host_key = 'ssh-rsa'
|
20
20
|
@timeout = 10
|
@@ -25,13 +25,11 @@ module Minicron
|
|
25
25
|
@ssh = Net::SSH.start(
|
26
26
|
@host,
|
27
27
|
@user,
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
:timeout => @timeout
|
34
|
-
}
|
28
|
+
:port => @port,
|
29
|
+
:keys => [@private_key],
|
30
|
+
:auth_methods => @auth_methods,
|
31
|
+
:host_key => @host_key,
|
32
|
+
:timeout => @timeout
|
35
33
|
)
|
36
34
|
end
|
37
35
|
|
data/spec/minicron/cli_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Minicron::CLI do
|
|
5
5
|
let(:thin_server) { Thin::Server }
|
6
6
|
|
7
7
|
describe '#server' do
|
8
|
-
it 'should start the minicron server' #do
|
8
|
+
it 'should start the minicron server' # do
|
9
9
|
# server.should_receive(:start!)
|
10
10
|
# server.should_receive(:running?)
|
11
11
|
# server.should_receive(:server)
|
@@ -42,7 +42,7 @@ describe Minicron::CLI do
|
|
42
42
|
it 'should return an error' do
|
43
43
|
Minicron.capture_output :type => :stderr do
|
44
44
|
expect do
|
45
|
-
Minicron::CLI.new.run(
|
45
|
+
Minicron::CLI.new.run(%w(lol --trace))
|
46
46
|
end.to raise_error SystemExit
|
47
47
|
end
|
48
48
|
end
|
@@ -52,7 +52,7 @@ describe Minicron::CLI do
|
|
52
52
|
it 'should raise ArgumentError' do
|
53
53
|
Minicron.capture_output :type => :stderr do
|
54
54
|
expect do
|
55
|
-
Minicron::CLI.new.run(
|
55
|
+
Minicron::CLI.new.run(%w(run --dry-run --trace))
|
56
56
|
end.to raise_error ArgumentError
|
57
57
|
end
|
58
58
|
end
|
@@ -80,7 +80,7 @@ describe Minicron::CLI do
|
|
80
80
|
it 'should return an error' do
|
81
81
|
Minicron.capture_output :type => :stderr do
|
82
82
|
expect do
|
83
|
-
Minicron::CLI.new.run(
|
83
|
+
Minicron::CLI.new.run(%w(lol --trace))
|
84
84
|
end.to raise_error SystemExit
|
85
85
|
end
|
86
86
|
end
|
@@ -14,7 +14,7 @@ describe Minicron::Transport::FayeClient do
|
|
14
14
|
|
15
15
|
describe '#ensure_em_running' do
|
16
16
|
context 'when eventmachine is not running' do
|
17
|
-
it 'should start eventmachine' #do
|
17
|
+
it 'should start eventmachine' # do
|
18
18
|
# eventmachine.stub(:reactor_running?).and_return(false, true)
|
19
19
|
# eventmachine.stub(:run)
|
20
20
|
# eventmachine.should_receive(:reactor_running?).twice
|
@@ -25,7 +25,7 @@ describe Minicron::Transport::FayeClient do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
context 'when eventmachine is running' do
|
28
|
-
it 'should not start eventmachine' #do
|
28
|
+
it 'should not start eventmachine' # do
|
29
29
|
# eventmachine.stub(:reactor_running?).and_return true
|
30
30
|
# eventmachine.should_receive(:reactor_running?).twice
|
31
31
|
|
@@ -46,8 +46,8 @@ describe Minicron::Transport::FayeClient do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
describe '#tidy_up'
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
49
|
+
it 'should stop eventmachine' do
|
50
|
+
eventmachine.should_receive(:stop)
|
51
|
+
client.new('http', '127.0.0.1', '80', '/test').tidy_up
|
52
|
+
end
|
53
|
+
end
|
data/spec/minicron_spec.rb
CHANGED
data/spec/valid_config.toml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minicron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James White
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rainbow
|
@@ -360,6 +360,20 @@ dependencies:
|
|
360
360
|
- - '>='
|
361
361
|
- !ruby/object:Gem::Version
|
362
362
|
version: 1.3.4
|
363
|
+
- !ruby/object:Gem::Dependency
|
364
|
+
name: insidious
|
365
|
+
requirement: !ruby/object:Gem::Requirement
|
366
|
+
requirements:
|
367
|
+
- - ~>
|
368
|
+
- !ruby/object:Gem::Version
|
369
|
+
version: '0.1'
|
370
|
+
type: :runtime
|
371
|
+
prerelease: false
|
372
|
+
version_requirements: !ruby/object:Gem::Requirement
|
373
|
+
requirements:
|
374
|
+
- - ~>
|
375
|
+
- !ruby/object:Gem::Version
|
376
|
+
version: '0.1'
|
363
377
|
- !ruby/object:Gem::Dependency
|
364
378
|
name: mysql2
|
365
379
|
requirement: !ruby/object:Gem::Requirement
|