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
@@ -7,7 +7,7 @@
7
7
  #
8
8
  # Host: 127.0.0.1 (MySQL 5.6.16)
9
9
  # Database: minicron
10
- # Generation Time: 2014-03-29 07:06:21 +0000
10
+ # Generation Time: 2014-04-01 03:35:39 +0000
11
11
  # ************************************************************
12
12
 
13
13
 
@@ -23,8 +23,10 @@
23
23
  # Dump of table alerts
24
24
  # ------------------------------------------------------------
25
25
 
26
+ DROP TABLE IF EXISTS `alerts`;
27
+
26
28
  CREATE TABLE `alerts` (
27
- `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
29
+ `id` int(11) NOT NULL AUTO_INCREMENT,
28
30
  `schedule_id` int(11) DEFAULT NULL,
29
31
  `execution_id` int(11) DEFAULT NULL,
30
32
  `kind` varchar(4) NOT NULL DEFAULT '',
@@ -32,11 +34,11 @@ CREATE TABLE `alerts` (
32
34
  `medium` varchar(9) NOT NULL DEFAULT '',
33
35
  `sent_at` datetime NOT NULL,
34
36
  PRIMARY KEY (`id`),
35
- KEY `schedule_id` (`schedule_id`),
36
- KEY `execution_id` (`execution_id`),
37
- KEY `kind` (`kind`),
38
- KEY `expected_at` (`expected_at`),
39
- KEY `medium` (`medium`)
37
+ KEY `execution_id` (`execution_id`) USING BTREE,
38
+ KEY `expected_at` (`expected_at`) USING BTREE,
39
+ KEY `kind` (`kind`) USING BTREE,
40
+ KEY `medium` (`medium`) USING BTREE,
41
+ KEY `schedule_id` (`schedule_id`) USING BTREE
40
42
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
41
43
 
42
44
 
@@ -44,6 +46,8 @@ CREATE TABLE `alerts` (
44
46
  # Dump of table executions
45
47
  # ------------------------------------------------------------
46
48
 
49
+ DROP TABLE IF EXISTS `executions`;
50
+
47
51
  CREATE TABLE `executions` (
48
52
  `id` int(11) NOT NULL AUTO_INCREMENT,
49
53
  `job_id` int(11) NOT NULL,
@@ -52,10 +56,10 @@ CREATE TABLE `executions` (
52
56
  `finished_at` datetime DEFAULT NULL,
53
57
  `exit_status` int(11) DEFAULT NULL,
54
58
  PRIMARY KEY (`id`),
55
- KEY `created_at` (`created_at`),
56
- KEY `finished_at` (`finished_at`),
57
- KEY `job_id` (`job_id`),
58
- KEY `started_at` (`started_at`)
59
+ KEY `created_at` (`created_at`) USING BTREE,
60
+ KEY `finished_at` (`finished_at`) USING BTREE,
61
+ KEY `job_id` (`job_id`) USING BTREE,
62
+ KEY `started_at` (`started_at`) USING BTREE
59
63
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
60
64
 
61
65
 
@@ -63,17 +67,19 @@ CREATE TABLE `executions` (
63
67
  # Dump of table hosts
64
68
  # ------------------------------------------------------------
65
69
 
70
+ DROP TABLE IF EXISTS `hosts`;
71
+
66
72
  CREATE TABLE `hosts` (
67
73
  `id` int(11) NOT NULL AUTO_INCREMENT,
68
74
  `name` varchar(255) DEFAULT NULL,
69
75
  `fqdn` varchar(255) NOT NULL DEFAULT '',
70
76
  `host` varchar(255) NOT NULL DEFAULT '',
71
- `port` int(11) NOT NULL DEFAULT '22',
77
+ `port` int(11) NOT NULL,
72
78
  `public_key` text,
73
79
  `created_at` datetime NOT NULL,
74
80
  `updated_at` datetime NOT NULL,
75
81
  PRIMARY KEY (`id`),
76
- KEY `hostname` (`fqdn`)
82
+ KEY `hostname` (`fqdn`) USING BTREE
77
83
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
78
84
 
79
85
 
@@ -81,6 +87,8 @@ CREATE TABLE `hosts` (
81
87
  # Dump of table job_execution_outputs
82
88
  # ------------------------------------------------------------
83
89
 
90
+ DROP TABLE IF EXISTS `job_execution_outputs`;
91
+
84
92
  CREATE TABLE `job_execution_outputs` (
85
93
  `id` int(11) NOT NULL AUTO_INCREMENT,
86
94
  `execution_id` int(11) NOT NULL,
@@ -88,8 +96,8 @@ CREATE TABLE `job_execution_outputs` (
88
96
  `output` text NOT NULL,
89
97
  `timestamp` datetime NOT NULL,
90
98
  PRIMARY KEY (`id`),
91
- KEY `execution_id` (`execution_id`),
92
- KEY `seq` (`seq`)
99
+ KEY `execution_id` (`execution_id`) USING BTREE,
100
+ KEY `seq` (`seq`) USING BTREE
93
101
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
94
102
 
95
103
 
@@ -97,6 +105,8 @@ CREATE TABLE `job_execution_outputs` (
97
105
  # Dump of table jobs
98
106
  # ------------------------------------------------------------
99
107
 
108
+ DROP TABLE IF EXISTS `jobs`;
109
+
100
110
  CREATE TABLE `jobs` (
101
111
  `id` int(11) NOT NULL AUTO_INCREMENT,
102
112
  `job_hash` varchar(32) NOT NULL DEFAULT '',
@@ -106,9 +116,9 @@ CREATE TABLE `jobs` (
106
116
  `created_at` datetime NOT NULL,
107
117
  `updated_at` datetime NOT NULL,
108
118
  PRIMARY KEY (`id`),
109
- UNIQUE KEY `job_hash` (`job_hash`),
110
- KEY `created_at` (`created_at`),
111
- KEY `host_id` (`host_id`)
119
+ UNIQUE KEY `job_hash` (`job_hash`) USING BTREE,
120
+ KEY `created_at` (`created_at`) USING BTREE,
121
+ KEY `host_id` (`host_id`) USING BTREE
112
122
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
113
123
 
114
124
 
@@ -116,6 +126,8 @@ CREATE TABLE `jobs` (
116
126
  # Dump of table schedules
117
127
  # ------------------------------------------------------------
118
128
 
129
+ DROP TABLE IF EXISTS `schedules`;
130
+
119
131
  CREATE TABLE `schedules` (
120
132
  `id` int(11) NOT NULL AUTO_INCREMENT,
121
133
  `job_id` int(11) NOT NULL,
@@ -128,13 +140,13 @@ CREATE TABLE `schedules` (
128
140
  `created_at` datetime NOT NULL,
129
141
  `updated_at` datetime NOT NULL,
130
142
  PRIMARY KEY (`id`),
131
- KEY `day_of_the_month` (`day_of_the_month`),
132
- KEY `day_of_the_week` (`day_of_the_week`),
133
- KEY `hour` (`hour`),
134
- KEY `job_id` (`job_id`),
135
- KEY `minute` (`minute`),
136
- KEY `month` (`month`),
137
- KEY `special` (`special`)
143
+ KEY `day_of_the_month` (`day_of_the_month`) USING BTREE,
144
+ KEY `day_of_the_week` (`day_of_the_week`) USING BTREE,
145
+ KEY `hour` (`hour`) USING BTREE,
146
+ KEY `job_id` (`job_id`) USING BTREE,
147
+ KEY `minute` (`minute`) USING BTREE,
148
+ KEY `month` (`month`) USING BTREE,
149
+ KEY `special` (`special`) USING BTREE
138
150
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
139
151
 
140
152
 
@@ -142,6 +154,8 @@ CREATE TABLE `schedules` (
142
154
  # Dump of table schema_migrations
143
155
  # ------------------------------------------------------------
144
156
 
157
+ DROP TABLE IF EXISTS `schema_migrations`;
158
+
145
159
  CREATE TABLE `schema_migrations` (
146
160
  `version` varchar(255) NOT NULL,
147
161
  UNIQUE KEY `unique_schema_migrations` (`version`)
@@ -149,6 +163,20 @@ CREATE TABLE `schema_migrations` (
149
163
 
150
164
 
151
165
 
166
+ # Dump of table users
167
+ # ------------------------------------------------------------
168
+
169
+ DROP TABLE IF EXISTS `users`;
170
+
171
+ CREATE TABLE `users` (
172
+ `id` int(11) NOT NULL AUTO_INCREMENT,
173
+ `email` int(11) NOT NULL,
174
+ `password` int(11) NOT NULL,
175
+ PRIMARY KEY (`id`)
176
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
177
+
178
+
179
+
152
180
 
153
181
  /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
154
182
  /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
@@ -2,7 +2,7 @@ module Minicron
2
2
  module Hub
3
3
  class Execution < ActiveRecord::Base
4
4
  belongs_to :job
5
- has_many :job_execution_outputs, :dependent => :delete_all
5
+ has_many :job_execution_outputs, :dependent => :destroy
6
6
  end
7
7
  end
8
8
  end
@@ -1,7 +1,16 @@
1
1
  module Minicron
2
2
  module Hub
3
3
  class Host < ActiveRecord::Base
4
- has_many :jobs, :dependent => :delete_all
4
+ has_many :jobs, :dependent => :destroy
5
+
6
+ # Default the name of the host to the fqdn itself if no name is set
7
+ def name
8
+ if read_attribute(:name) == '' || read_attribute(:name).nil?
9
+ read_attribute(:fqdn)
10
+ else
11
+ read_attribute(:name)
12
+ end
13
+ end
5
14
  end
6
15
  end
7
16
  end
@@ -2,12 +2,12 @@ module Minicron
2
2
  module Hub
3
3
  class Job < ActiveRecord::Base
4
4
  belongs_to :host
5
- has_many :executions, :dependent => :delete_all
6
- has_many :schedules, :dependent => :delete_all
5
+ has_many :executions, :dependent => :destroy
6
+ has_many :schedules, :dependent => :destroy
7
7
 
8
8
  # Default the name of the command to the command itself if no name is set
9
9
  def name
10
- if read_attribute(:name) == '' || read_attribute(:name) == nil
10
+ if read_attribute(:name) == '' || read_attribute(:name).nil?
11
11
  read_attribute(:command)
12
12
  else
13
13
  read_attribute(:name)
@@ -14,7 +14,7 @@ module Minicron
14
14
  # @return string
15
15
  def self.format(schedule)
16
16
  # If it's not a 'special' schedule then build up the full schedule string
17
- if schedule.special == '' || schedule.special == nil
17
+ if schedule.special == '' || schedule.special.nil?
18
18
  "#{schedule.minute} #{schedule.hour} #{schedule.day_of_the_month} #{schedule.month} #{schedule.day_of_the_week}"
19
19
  else
20
20
  schedule.special
@@ -1,75 +1,79 @@
1
- class Minicron::Hub::App::ExecutionSerializer
2
- def initialize(executions)
3
- @executions = executions
4
- end
1
+ module Minicron
2
+ module Hub
3
+ class ExecutionSerializer
4
+ def initialize(executions)
5
+ @executions = executions
6
+ end
5
7
 
6
- def serialize
7
- @response = {
8
- :executions => [],
9
- :jobs => [],
10
- :job_execution_outputs => [],
11
- :hosts => []
12
- }
13
-
14
- if @executions.respond_to? :each
15
- @executions.each do |execution|
16
- do_serialization(execution)
8
+ def serialize
9
+ @response = {
10
+ :executions => [],
11
+ :jobs => [],
12
+ :job_execution_outputs => [],
13
+ :hosts => []
14
+ }
15
+
16
+ if @executions.respond_to? :each
17
+ @executions.each do |execution|
18
+ do_serialization(execution)
19
+ end
20
+ else
21
+ do_serialization(@executions)
22
+ end
23
+
24
+ @response
17
25
  end
18
- else
19
- do_serialization(@executions)
20
- end
21
26
 
22
- @response
23
- end
27
+ def do_serialization(execution)
28
+ new_execution = {}
24
29
 
25
- def do_serialization(execution)
26
- new_execution = {}
30
+ # Add all the normal attributes of the execution
31
+ execution.attributes.each do |key, value|
32
+ # Remove _id from keys
33
+ key = key[-3, 3] == '_id' ? key[0..-4] : key
27
34
 
28
- # Add all the normal attributes of the execution
29
- execution.attributes.each do |key, value|
30
- # Remove _id from keys
31
- key = key[-3, 3] == '_id' ? key[0..-4] : key
35
+ new_execution[key] = value
36
+ end
32
37
 
33
- new_execution[key] = value
34
- end
38
+ # Set up the job execution output ids array
39
+ new_execution[:job_execution_outputs] = []
35
40
 
36
- # Set up the job execution output ids array
37
- new_execution[:job_execution_outputs] = []
41
+ # Add the job to the sideloaded data
42
+ new_job = {}
43
+ execution.job.attributes.each do |key, value|
44
+ # To make our name method in the model work :/
45
+ value = execution.job.name if key == 'name'
38
46
 
39
- # Add the job to the sideloaded data
40
- new_job = {}
41
- execution.job.attributes.each do |key, value|
42
- # To make our name method in the model work :/
43
- value = execution.job.name if key == 'name'
47
+ # Remove _id from keys
48
+ key = key[-3, 3] == '_id' ? key[0..-4] : key
44
49
 
45
- # Remove _id from keys
46
- key = key[-3, 3] == '_id' ? key[0..-4] : key
50
+ new_job[key] = value
51
+ end
47
52
 
48
- new_job[key] = value
49
- end
53
+ # Append the new job to the @response
54
+ @response[:jobs].push(new_job)
50
55
 
51
- # Append the new job to the @response
52
- @response[:jobs].push(new_job)
56
+ # Append the job host to the @response
57
+ @response[:hosts].push(execution.job.host)
53
58
 
54
- # Append the job host to the @response
55
- @response[:hosts].push(execution.job.host)
59
+ # Add the job execution outputs to the sideloaded data and the ids to
60
+ # the execution
61
+ execution.job_execution_outputs.each do |job_execution_output|
62
+ new_job_execution_output = {}
56
63
 
57
- # Add the job execution outputs to the sideloaded data and the ids to
58
- # the execution
59
- execution.job_execution_outputs.each do |job_execution_output|
60
- new_job_execution_output = {}
64
+ job_execution_output.attributes.each do |key, value|
65
+ # Remove _id from keys
66
+ key = key[-3, 3] == '_id' ? key[0..-4] : key
67
+ new_job_execution_output[key] = value
68
+ end
61
69
 
62
- job_execution_output.attributes.each do |key, value|
63
- # Remove _id from keys
64
- key = key[-3, 3] == '_id' ? key[0..-4] : key
65
- new_job_execution_output[key] = value
66
- end
70
+ @response[:job_execution_outputs].push(new_job_execution_output)
71
+ new_execution[:job_execution_outputs].push(job_execution_output.id)
72
+ end
67
73
 
68
- @response[:job_execution_outputs].push(new_job_execution_output)
69
- new_execution[:job_execution_outputs].push(job_execution_output.id)
74
+ # Append the new execution to the @response
75
+ @response[:executions].push(new_execution)
76
+ end
70
77
  end
71
-
72
- # Append the new execution to the @response
73
- @response[:executions].push(new_execution)
74
78
  end
75
79
  end
@@ -1,57 +1,64 @@
1
- class Minicron::Hub::App::HostSerializer
2
- def initialize(hosts)
3
- @hosts = hosts
4
- end
1
+ module Minicron
2
+ module Hub
3
+ class HostSerializer
4
+ def initialize(hosts)
5
+ @hosts = hosts
6
+ end
7
+
8
+ def serialize
9
+ @response = {
10
+ :hosts => [],
11
+ :jobs => []
12
+ }
5
13
 
6
- def serialize
7
- @response = {
8
- :hosts => [],
9
- :jobs => []
10
- }
14
+ if @hosts.respond_to? :each
15
+ @hosts.each do |host|
16
+ do_serialization(host)
17
+ end
18
+ else
19
+ do_serialization(@hosts)
20
+ end
11
21
 
12
- if @hosts.respond_to? :each
13
- @hosts.each do |host|
14
- do_serialization(host)
22
+ @response
15
23
  end
16
- else
17
- do_serialization(@hosts)
18
- end
19
24
 
20
- @response
21
- end
25
+ def do_serialization(host)
26
+ new_host = {}
22
27
 
23
- def do_serialization(host)
24
- new_host = {}
28
+ # Add all the normal attributes of the host
29
+ host.attributes.each do |key, value|
30
+ # To make our name method in the model work :/
31
+ value = host.name if key == 'name'
25
32
 
26
- # Add all the normal attributes of the host
27
- host.attributes.each do |key, value|
28
- new_host[key] = value
29
- end
33
+ new_host[key] = value
34
+ end
30
35
 
31
- # Set up the job host output ids array
32
- new_host[:jobs] = []
36
+ # Set up the job host output ids array
37
+ new_host[:jobs] = []
33
38
 
34
- # Add the jobs to the sideloaded data and the ids to
35
- # the host
36
- host.jobs.each do |job|
37
- new_job = {}
39
+ # Add the jobs to the sideloaded data and the ids to
40
+ # the host
41
+ host.jobs.each do |job|
42
+ new_job = {}
38
43
 
39
- job.attributes.each do |key, value|
40
- # To make our name method in the model work :/
41
- value = job.name if key == 'name'
44
+ job.attributes.each do |key, value|
45
+ # To make our name method in the model work :/
46
+ value = job.name if key == 'name'
42
47
 
43
- # Remove _id from keys
44
- key = key[-3, 3] == '_id' ? key[0..-4] : key
48
+ # Remove _id from keys
49
+ key = key[-3, 3] == '_id' ? key[0..-4] : key
45
50
 
46
- # Append the job
47
- new_job[key] = value
48
- end
51
+ # Append the job
52
+ new_job[key] = value
53
+ end
49
54
 
50
- @response[:jobs].push(new_job)
51
- new_host[:jobs].push(job.id)
52
- end
55
+ @response[:jobs].push(new_job)
56
+ new_host[:jobs].push(job.id)
57
+ end
53
58
 
54
- # Append the new host to the @responseh
55
- @response[:hosts].push(new_host)
59
+ # Append the new host to the @responseh
60
+ @response[:hosts].push(new_host)
61
+ end
62
+ end
56
63
  end
57
64
  end