minicron 0.1.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,104 +1,108 @@
1
- class Minicron::Hub::App::JobSerializer
2
- def initialize(jobs)
3
- @jobs = jobs
4
- end
1
+ module Minicron
2
+ module Hub
3
+ class JobSerializer
4
+ def initialize(jobs)
5
+ @jobs = jobs
6
+ end
5
7
 
6
- def serialize
7
- @response = {
8
- :jobs => [],
9
- :hosts => [],
10
- :executions => [],
11
- :schedules => []
12
- }
13
-
14
- if @jobs.respond_to? :each
15
- @jobs.each do |job|
16
- do_serialization(job)
8
+ def serialize
9
+ @response = {
10
+ :jobs => [],
11
+ :hosts => [],
12
+ :executions => [],
13
+ :schedules => []
14
+ }
15
+
16
+ if @jobs.respond_to? :each
17
+ @jobs.each do |job|
18
+ do_serialization(job)
19
+ end
20
+ else
21
+ do_serialization(@jobs)
22
+ end
23
+
24
+ @response
17
25
  end
18
- else
19
- do_serialization(@jobs)
20
- end
21
26
 
22
- @response
23
- end
27
+ def do_serialization(job)
28
+ new_job = {}
24
29
 
25
- def do_serialization(job)
26
- new_job = {}
30
+ # Add all the normal attributes of the job
31
+ job.attributes.each do |key, value|
32
+ # To make our name method in the model work :/
33
+ value = job.name if key == 'name'
27
34
 
28
- # Add all the normal attributes of the job
29
- job.attributes.each do |key, value|
30
- # To make our name method in the model work :/
31
- value = job.name if key == 'name'
35
+ # Remove _id from keys
36
+ key = key[-3, 3] == '_id' ? key[0..-4] : key
32
37
 
33
- # Remove _id from keys
34
- key = key[-3, 3] == '_id' ? key[0..-4] : key
38
+ new_job[key] = value
39
+ end
35
40
 
36
- new_job[key] = value
37
- end
41
+ # Set up the execution ids array
42
+ new_job[:executions] = []
38
43
 
39
- # Set up the execution ids array
40
- new_job[:executions] = []
44
+ # Set up the schedules ids array
45
+ new_job[:schedules] = []
41
46
 
42
- # Set up the schedules ids array
43
- new_job[:schedules] = []
47
+ # Add the host to the sideloaded data
48
+ new_host = {}
49
+ job.host.attributes.each do |key, value|
50
+ # To make our name method in the model work :/
51
+ value = job.host.name if key == 'name'
44
52
 
45
- # Add the host to the sideloaded data
46
- new_host = {}
47
- job.host.attributes.each do |key, value|
48
- # To make our name method in the model work :/
49
- value = job.host.name if key == 'name'
53
+ # Remove _id from keys
54
+ key = key[-3, 3] == '_id' ? key[0..-4] : key
50
55
 
51
- # Remove _id from keys
52
- key = key[-3, 3] == '_id' ? key[0..-4] : key
56
+ new_host[key] = value
57
+ end
53
58
 
54
- new_host[key] = value
55
- end
59
+ # Append the new host to the @response
60
+ @response[:hosts].push(new_host)
56
61
 
57
- # Append the new host to the @response
58
- @response[:hosts].push(new_host)
62
+ # Add the schedules to the sideloaded data and the ids to
63
+ # the job
64
+ job.schedules.each do |schedule|
65
+ new_schedule = {}
59
66
 
60
- # Add the schedules to the sideloaded data and the ids to
61
- # the job
62
- job.schedules.each do |schedule|
63
- new_schedule = {}
67
+ schedule.attributes.each do |key, value|
68
+ # Remove _id from keys
69
+ key = key[-3, 3] == '_id' ? key[0..-4] : key
64
70
 
65
- schedule.attributes.each do |key, value|
66
- # Remove _id from keys
67
- key = key[-3, 3] == '_id' ? key[0..-4] : key
71
+ new_schedule[key] = value
72
+ end
68
73
 
69
- new_schedule[key] = value
70
- end
74
+ # Add the formatted version of the schedule
75
+ new_schedule['formatted'] = schedule.formatted
71
76
 
72
- # Add the formatted version of the schedule
73
- new_schedule['formatted'] = schedule.formatted
77
+ @response[:schedules].push(new_schedule)
78
+ new_job[:schedules].push(schedule.id)
79
+ end
74
80
 
75
- @response[:schedules].push(new_schedule)
76
- new_job[:schedules].push(schedule.id)
77
- end
81
+ # Add the executions to the sideloaded data and the ids to
82
+ # the job
83
+ job.executions.each do |execution|
84
+ new_execution = {}
78
85
 
79
- # Add the executions to the sideloaded data and the ids to
80
- # the job
81
- job.executions.each do |execution|
82
- new_execution = {}
86
+ execution.attributes.each do |key, value|
87
+ # Remove _id from keys
88
+ key = key[-3, 3] == '_id' ? key[0..-4] : key
83
89
 
84
- execution.attributes.each do |key, value|
85
- # Remove _id from keys
86
- key = key[-3, 3] == '_id' ? key[0..-4] : key
90
+ new_execution[key] = value
91
+ end
87
92
 
88
- new_execution[key] = value
89
- end
93
+ # Also we need to add the job execution output ids
94
+ new_execution[:job_execution_outputs] = []
95
+ execution.job_execution_outputs.each do |job_execution_output|
96
+ new_execution[:job_execution_outputs].push(job_execution_output.id)
97
+ end
90
98
 
91
- # Also we need to add the job execution output ids
92
- new_execution[:job_execution_outputs] = []
93
- execution.job_execution_outputs.each do |job_execution_output|
94
- new_execution[:job_execution_outputs].push(job_execution_output.id)
95
- end
99
+ @response[:executions].push(new_execution)
100
+ new_job[:executions].push(execution.id)
101
+ end
96
102
 
97
- @response[:executions].push(new_execution)
98
- new_job[:executions].push(execution.id)
103
+ # Append the new job to the @responseh
104
+ @response[:jobs].push(new_job)
105
+ end
99
106
  end
100
-
101
- # Append the new job to the @responseh
102
- @response[:jobs].push(new_job)
103
107
  end
104
108
  end
@@ -1,48 +1,52 @@
1
- class Minicron::Hub::App::JobExecutionOutputSerializer
2
- def initialize(job_execution_outputs)
3
- @job_execution_outputs = job_execution_outputs
4
- end
5
-
6
- def serialize
7
- @response = {
8
- :job_execution_outputs => [],
9
- :executions => []
10
- }
11
-
12
- if @job_execution_outputs.respond_to? :each
13
- @job_execution_outputs.each do |job_execution_output|
14
- do_serialization(job_execution_output)
1
+ module Minicron
2
+ module Hub
3
+ class JobExecutionOutputSerializer
4
+ def initialize(job_execution_outputs)
5
+ @job_execution_outputs = job_execution_outputs
15
6
  end
16
- else
17
- do_serialization(@job_execution_outputs)
18
- end
19
7
 
20
- @response
21
- end
8
+ def serialize
9
+ @response = {
10
+ :job_execution_outputs => [],
11
+ :executions => []
12
+ }
13
+
14
+ if @job_execution_outputs.respond_to? :each
15
+ @job_execution_outputs.each do |job_execution_output|
16
+ do_serialization(job_execution_output)
17
+ end
18
+ else
19
+ do_serialization(@job_execution_outputs)
20
+ end
21
+
22
+ @response
23
+ end
22
24
 
23
- def do_serialization(job_execution_output)
24
- new_job_execution_output = {}
25
+ def do_serialization(job_execution_output)
26
+ new_job_execution_output = {}
25
27
 
26
- # Add all the normal attributes of the job_execution_output
27
- job_execution_output.attributes.each do |key, value|
28
- # Remove _id from keys
29
- key = key[-3, 3] == '_id' ? key[0..-4] : key
30
- new_job_execution_output[key] = value
31
- end
28
+ # Add all the normal attributes of the job_execution_output
29
+ job_execution_output.attributes.each do |key, value|
30
+ # Remove _id from keys
31
+ key = key[-3, 3] == '_id' ? key[0..-4] : key
32
+ new_job_execution_output[key] = value
33
+ end
32
34
 
33
- # Add the execution to the sideloaded data
34
- new_execution = {}
35
- job_execution_output.execution.attributes.each do |key, value|
36
- # Remove _id from keys
37
- key = key[-3, 3] == '_id' ? key[0..-4] : key
35
+ # Add the execution to the sideloaded data
36
+ new_execution = {}
37
+ job_execution_output.execution.attributes.each do |key, value|
38
+ # Remove _id from keys
39
+ key = key[-3, 3] == '_id' ? key[0..-4] : key
38
40
 
39
- new_execution[key] = value
40
- end
41
+ new_execution[key] = value
42
+ end
41
43
 
42
- # Append the new execution to the @response
43
- @response[:executions].push(new_execution)
44
+ # Append the new execution to the @response
45
+ @response[:executions].push(new_execution)
44
46
 
45
- # Append the new job_execution_output to the @response
46
- @response[:job_execution_outputs].push(new_job_execution_output)
47
+ # Append the new job_execution_output to the @response
48
+ @response[:job_execution_outputs].push(new_job_execution_output)
49
+ end
50
+ end
47
51
  end
48
52
  end
@@ -1,68 +1,72 @@
1
- class Minicron::Hub::App::ScheduleSerializer
2
- def initialize(schedules)
3
- @schedules = schedules
4
- end
1
+ module Minicron
2
+ module Hub
3
+ class ScheduleSerializer
4
+ def initialize(schedules)
5
+ @schedules = schedules
6
+ end
5
7
 
6
- def serialize
7
- @response = {
8
- :schedules => [],
9
- :jobs => []
10
- }
8
+ def serialize
9
+ @response = {
10
+ :schedules => [],
11
+ :jobs => []
12
+ }
11
13
 
12
- if @schedules.respond_to? :each
13
- @schedules.each do |schedule|
14
- do_serialization(schedule)
15
- end
16
- else
17
- do_serialization(@schedules)
18
- end
14
+ if @schedules.respond_to? :each
15
+ @schedules.each do |schedule|
16
+ do_serialization(schedule)
17
+ end
18
+ else
19
+ do_serialization(@schedules)
20
+ end
19
21
 
20
- @response
21
- end
22
+ @response
23
+ end
22
24
 
23
- def do_serialization(schedule)
24
- new_schedule = {}
25
+ def do_serialization(schedule)
26
+ new_schedule = {}
25
27
 
26
- # Add all the normal attributes of the schedule
27
- schedule.attributes.each do |key, value|
28
- # Remove _id from keys
29
- key = key[-3, 3] == '_id' ? key[0..-4] : key
28
+ # Add all the normal attributes of the schedule
29
+ schedule.attributes.each do |key, value|
30
+ # Remove _id from keys
31
+ key = key[-3, 3] == '_id' ? key[0..-4] : key
30
32
 
31
- new_schedule[key] = value
32
- end
33
+ new_schedule[key] = value
34
+ end
33
35
 
34
- # Add the formatted version of the schedule
35
- new_schedule['formatted'] = schedule.formatted
36
+ # Add the formatted version of the schedule
37
+ new_schedule['formatted'] = schedule.formatted
36
38
 
37
- # Add the schedule job to the sideloaded data
38
- new_job = {
39
- :schedules => [],
40
- :executions => []
41
- }
42
- schedule.job.attributes.each do |key, value|
43
- # To make our name method in the model work :/
44
- value = schedule.job.name if key == 'name'
39
+ # Add the schedule job to the sideloaded data
40
+ new_job = {
41
+ :schedules => [],
42
+ :executions => []
43
+ }
44
+ schedule.job.attributes.each do |key, value|
45
+ # To make our name method in the model work :/
46
+ value = schedule.job.name if key == 'name'
45
47
 
46
- # Remove _id from keys
47
- key = key[-3, 3] == '_id' ? key[0..-4] : key
48
+ # Remove _id from keys
49
+ key = key[-3, 3] == '_id' ? key[0..-4] : key
48
50
 
49
- new_job[key] = value
50
- end
51
+ new_job[key] = value
52
+ end
51
53
 
52
- # Add the ids of each job schedule to the job
53
- schedule.job.schedules.each do |s|
54
- new_job[:schedules].push(s.id)
55
- end
54
+ # Add the ids of each job schedule to the job
55
+ schedule.job.schedules.each do |s|
56
+ new_job[:schedules].push(s.id)
57
+ end
56
58
 
57
- # Add the ids of each job execution to the job
58
- schedule.job.executions.each do |execution|
59
- new_job[:executions].push(execution.id)
60
- end
59
+ # Add the ids of each job execution to the job
60
+ schedule.job.executions.each do |execution|
61
+ new_job[:executions].push(execution.id)
62
+ end
61
63
 
62
- # Append the new job to the @response
63
- @response[:jobs].push(new_job)
64
+ # Append the new job to the @response
65
+ @response[:jobs].push(new_job)
64
66
 
65
- # Append the new schedule to the @responseh
66
- @response[:schedules].push(new_schedule)
67
+ # Append the new schedule to the @responseh
68
+ @response[:schedules].push(new_schedule)
69
+ end
70
+ end
67
71
  end
68
72
  end
@@ -1,5 +1,11 @@
1
1
  <script type="text/x-handlebars" id="executions/index">
2
- Nothing to see here, why not set up a {{#link-to 'jobs'}}job{{/link-to}}?
2
+ <header>
3
+ <h2>Welcome to minicron!</h2>
4
+ </header>
5
+ <hr/>
6
+
7
+ To get started you need to {{#link-to 'hosts.new'}}set up a host{{/link-to}} and
8
+ then you can {{#link-to 'jobs.new'}}add your first job{{/link-to}}!
3
9
  </script>
4
10
 
5
11
  <script type="text/x-handlebars" id="execution/index">
@@ -150,7 +150,7 @@
150
150
  <div class="form-group">
151
151
  <label class="col-sm-2 control-label">Port</label>
152
152
  <div class="col-sm-10">
153
- {{input value=port type="text" class="form-control" placeholder="The port to connect on, if empty this is assumed to be 22"}}
153
+ {{input value=port type="text" class="form-control" placeholder="The port to connect on e.g 22"}}
154
154
  </div>
155
155
  </div>
156
156
  <div class="form-group">
@@ -192,7 +192,7 @@
192
192
  <div class="form-group">
193
193
  <label class="col-sm-2 control-label">Port</label>
194
194
  <div class="col-sm-10">
195
- {{input value=port type="text" class="form-control" placeholder="The port to connect on, if empty this is assumed to be 22"}}
195
+ {{input value=port type="text" class="form-control" placeholder="The port to connect on e.g 22"}}
196
196
  </div>
197
197
  </div>
198
198
  <div class="form-group">
@@ -313,7 +313,7 @@
313
313
 
314
314
  <script type="text/x-handlebars" id="schedule/index">
315
315
  <header class="clearfix">
316
- <h2 class="pull-left">Schedule #{{id}} for Job '{{job.name}}'</h2>
316
+ <h2 class="pull-left">View Schedule #{{id}}</h2>
317
317
  <a {{action 'delete' this}} class="pull-right btn btn-danger btn-sm">Delete</a>
318
318
  {{#link-to 'schedule.edit' id class="pull-right btn btn-warning btn-sm"}}Edit{{/link-to}}
319
319
  </header>
@@ -329,7 +329,7 @@
329
329
 
330
330
  <script type="text/x-handlebars" id="schedules/new">
331
331
  <header>
332
- <h2>Add New Schedule for Job '{{name}}'</h2>
332
+ <h2>Add New Schedule</h2>
333
333
  </header>
334
334
  <hr/>
335
335
 
@@ -341,7 +341,7 @@
341
341
 
342
342
  <script type="text/x-handlebars" id="schedule/edit">
343
343
  <header class="clearfix">
344
- <h2 class="pull-left">Edit Schedule #{{id}} for Job '{{job.name}}'</h2>
344
+ <h2 class="pull-left">Edit Schedule #{{id}}</h2>
345
345
  <a {{action 'delete' this}} class="pull-right btn btn-danger btn-sm">Delete</a>
346
346
  </header>
347
347
  <hr/>