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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +96 -43
  3. data/Rakefile +9 -1
  4. data/lib/minicron.rb +9 -4
  5. data/lib/minicron/alert.rb +2 -1
  6. data/lib/minicron/alert/email.rb +7 -2
  7. data/lib/minicron/alert/pagerduty.rb +3 -2
  8. data/lib/minicron/alert/sms.rb +2 -1
  9. data/lib/minicron/cli.rb +49 -19
  10. data/lib/minicron/constants.rb +2 -1
  11. data/lib/minicron/cron.rb +6 -6
  12. data/lib/minicron/hub/app.rb +8 -8
  13. data/lib/minicron/hub/assets/app/controllers/executions.js +4 -3
  14. data/lib/minicron/hub/assets/app/controllers/hosts.js +4 -4
  15. data/lib/minicron/hub/assets/app/controllers/jobs.js +4 -4
  16. data/lib/minicron/hub/assets/app/controllers/schedules.js +4 -1
  17. data/lib/minicron/hub/controllers/api/executions.rb +4 -4
  18. data/lib/minicron/hub/controllers/api/hosts.rb +18 -5
  19. data/lib/minicron/hub/controllers/api/job_execution_outputs.rb +2 -2
  20. data/lib/minicron/hub/controllers/api/jobs.rb +8 -8
  21. data/lib/minicron/hub/controllers/api/schedule.rb +10 -10
  22. data/lib/minicron/hub/db/schema.rb +70 -65
  23. data/lib/minicron/hub/db/schema.sql +53 -25
  24. data/lib/minicron/hub/models/execution.rb +1 -1
  25. data/lib/minicron/hub/models/host.rb +10 -1
  26. data/lib/minicron/hub/models/job.rb +3 -3
  27. data/lib/minicron/hub/models/schedule.rb +1 -1
  28. data/lib/minicron/hub/serializers/execution.rb +61 -57
  29. data/lib/minicron/hub/serializers/host.rb +49 -42
  30. data/lib/minicron/hub/serializers/job.rb +82 -78
  31. data/lib/minicron/hub/serializers/job_execution_output.rb +42 -38
  32. data/lib/minicron/hub/serializers/schedule.rb +56 -52
  33. data/lib/minicron/hub/views/handlebars/executions.erb +7 -1
  34. data/lib/minicron/hub/views/handlebars/hosts.erb +2 -2
  35. data/lib/minicron/hub/views/handlebars/schedules.erb +3 -3
  36. data/lib/minicron/monitor.rb +4 -4
  37. data/lib/minicron/transport/client.rb +6 -6
  38. data/lib/minicron/transport/faye/client.rb +4 -4
  39. data/lib/minicron/transport/faye/extensions/job_handler.rb +3 -2
  40. data/lib/minicron/transport/faye/server.rb +1 -0
  41. data/lib/minicron/transport/server.rb +2 -2
  42. data/lib/minicron/transport/ssh.rb +6 -8
  43. data/spec/minicron/cli_spec.rb +4 -4
  44. data/spec/minicron/transport/client_spec.rb +2 -2
  45. data/spec/minicron/transport/faye/client_spec.rb +7 -7
  46. data/spec/minicron/transport/server_spec.rb +1 -1
  47. data/spec/minicron_spec.rb +2 -1
  48. data/spec/valid_config.toml +1 -0
  49. metadata +16 -2
@@ -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
- raise Exception, "The database #{Minicron.config['database']['type']} is not supported"
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 do
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("%Y-%m-%d %H:%M:%S"),
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({ :message => data.to_json })
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 not host
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
@@ -32,6 +32,7 @@ module Minicron
32
32
  end
33
33
 
34
34
  private
35
+
35
36
  def add_faye_events
36
37
  @server.on(:handshake) do |client_id|
37
38
  p [:handshake, client_id] if Minicron.config['global']['verbose']
@@ -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 != nil
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 != nil
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 = `whoami`.strip
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
- :port => @port,
30
- :keys => [@private_key],
31
- :auth_methods => @auth_methods,
32
- :host_key => @host_key,
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
 
@@ -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(['lol', '--trace'])
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(['run', '--dry-run', '--trace'])
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(['lol', '--trace'])
83
+ Minicron::CLI.new.run(%w(lol --trace))
84
84
  end.to raise_error SystemExit
85
85
  end
86
86
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Minicron::Transport::Client do
4
4
  describe '#setup' do
5
- it 'should send a setup message and ensure its delivery' #do
6
- #end
5
+ it 'should send a setup message and ensure its delivery' # do
6
+ # end
7
7
  end
8
8
  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
- 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
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
@@ -67,4 +67,4 @@ describe Minicron::Transport::Server do
67
67
  end
68
68
  end
69
69
  end
70
- end
70
+ end
@@ -78,7 +78,8 @@ describe Minicron do
78
78
  'server' => {
79
79
  'host' => '127.0.0.1',
80
80
  'port' => 9292,
81
- 'path' => '/'
81
+ 'path' => '/',
82
+ 'debug' => false
82
83
  },
83
84
  'database' => {
84
85
  'type' => 'mysql',
@@ -19,6 +19,7 @@ inactivity_timeout = 5
19
19
  host = "127.0.0.1"
20
20
  port = 9292
21
21
  path = "/"
22
+ debug = false
22
23
 
23
24
  # Database options
24
25
  [database]
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.1.1
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-01 00:00:00.000000000 Z
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