monitored_process 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +34 -0
- data/lib/generators/monitored_process_install/USAGE +8 -0
- data/lib/generators/monitored_process_install/monitored_process_install_generator.rb +15 -0
- data/lib/generators/monitored_process_install/templates/create_monitored_processes.rb +15 -0
- data/lib/monitored_process.rb +149 -146
- data/lib/monitored_process/version.rb +3 -0
- data/lib/tasks/monitored_process_tasks.rake +4 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20150603215041_create_monitored_processes.rb +15 -0
- data/test/dummy/db/migrate/create_monitored_processes.rb +15 -0
- data/test/dummy/db/schema.rb +28 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +13 -0
- data/test/dummy/log/test.log +30 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/generators/monitored_process_install_generator_test.rb +14 -0
- data/test/monitored_process_test.rb +7 -0
- data/test/test_helper.rb +19 -0
- metadata +133 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f2c256a81987d5ccea603a1e2734a3a4fd903a0
|
4
|
+
data.tar.gz: 2ee225057901afaaab5fe03bcdcf878ea11ccbeb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5642460d1c071c1c46637863694d25dc30556f9f3559417d383658a52f8869b04c2d05f54700a8b1776c72204ed2e06430df81a97bff7f53b2c1943c08d79b45
|
7
|
+
data.tar.gz: bb8a2fee836afd58c3e6d706a8c5a7a681de519bfa512c67fa05feaadbe43041bae81f90f3a98eb0704bc4c227678dffaa08d908bbbc5bf484ca9d27e460cc38
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Juan Manuel Vallejo
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'MonitoredProcess'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
|
4
|
+
class MonitoredProcessInstallGenerator < Rails::Generators::Base
|
5
|
+
include ::Rails::Generators::Migration
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
def create_migration_file
|
9
|
+
migration_template 'create_monitored_processes.rb', 'db/migrate/create_monitored_processes.rb'
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.next_migration_number(dirname)
|
13
|
+
::ActiveRecord::Generators::Base.next_migration_number(dirname)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateMonitoredProcesses < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :monitored_processes do |t|
|
4
|
+
t.string :name
|
5
|
+
t.integer :state
|
6
|
+
t.integer :pid
|
7
|
+
t.integer :elapsed_seconds
|
8
|
+
t.string :elapsed_time
|
9
|
+
t.text :console_output
|
10
|
+
t.text :error_description
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/monitored_process.rb
CHANGED
@@ -1,146 +1,149 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
end
|
1
|
+
module MonitoredProcess
|
2
|
+
|
3
|
+
class Base < ActiveRecord::Base
|
4
|
+
self.table_name = 'monitored_processes'
|
5
|
+
|
6
|
+
attr_accessor :log_lambda
|
7
|
+
|
8
|
+
STATE = { :running => 1, :finished => 2, :finished_with_errors => 3 }
|
9
|
+
|
10
|
+
# VALIDATIONS
|
11
|
+
validates_presence_of :name, :state, :pid
|
12
|
+
|
13
|
+
def self.start_process
|
14
|
+
p = MonitoredProcess.new
|
15
|
+
p.name = self.to_s
|
16
|
+
p.state = STATE[:running]
|
17
|
+
p.pid = Process.pid
|
18
|
+
p.console_output = ""
|
19
|
+
p.save!
|
20
|
+
|
21
|
+
p.log_lambda = lambda do |message|
|
22
|
+
puts "#{DateTime.now} - #{message}"
|
23
|
+
end
|
24
|
+
|
25
|
+
return p
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.last_time_executed
|
29
|
+
p = MonitoredProcess.where(:name => self.to_s).last
|
30
|
+
return p.updated_at if !p.blank?
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.is_running_by_name? (process_name)
|
34
|
+
processes = MonitoredProcess.where(:name => process_name, :state => STATE[:running])
|
35
|
+
return false if processes.blank?
|
36
|
+
|
37
|
+
is_running = false
|
38
|
+
processes.each do |process|
|
39
|
+
begin
|
40
|
+
Process.getpgid(process.pid)
|
41
|
+
is_running = true
|
42
|
+
rescue Errno::ESRCH
|
43
|
+
process.finish_with_errors! "Unknown error / Process was terminated"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
return is_running
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.is_running?
|
50
|
+
return self.is_running_by_name? (self.name)
|
51
|
+
end
|
52
|
+
|
53
|
+
def finish!
|
54
|
+
set_finished_status
|
55
|
+
self.save!
|
56
|
+
end
|
57
|
+
|
58
|
+
def finish
|
59
|
+
set_finished_status
|
60
|
+
return self.save
|
61
|
+
end
|
62
|
+
|
63
|
+
def finish_with_errors! (error_description)
|
64
|
+
self.state = STATE[:finished_with_errors]
|
65
|
+
self.error_description = error_description
|
66
|
+
self.calculate_elapsed_seconds
|
67
|
+
self.save!
|
68
|
+
end
|
69
|
+
|
70
|
+
def calculate_elapsed_time
|
71
|
+
begin
|
72
|
+
hours_with_fraction = self.elapsed_seconds / 3600.0
|
73
|
+
hours = hours_with_fraction.truncate
|
74
|
+
minutes_with_fraction = (hours_with_fraction - hours) * 60
|
75
|
+
minutes = minutes_with_fraction.truncate
|
76
|
+
seconds_with_fraction = (minutes_with_fraction - minutes) * 60
|
77
|
+
seconds = seconds_with_fraction.truncate
|
78
|
+
|
79
|
+
self.elapsed_time = "#{hours.to_s.rjust(2, "0")}:#{minutes.to_s.rjust(2, "0")}:#{seconds.to_s.rjust(2, "0")}"
|
80
|
+
rescue
|
81
|
+
self.elapsed_time "00:00:00"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def calculate_elapsed_seconds
|
86
|
+
self.elapsed_seconds = Time.parse(DateTime.now.to_s) - Time.parse(self.created_at.to_s)
|
87
|
+
|
88
|
+
# Set elapsed time
|
89
|
+
self.calculate_elapsed_time
|
90
|
+
end
|
91
|
+
|
92
|
+
def output(text)
|
93
|
+
self.console_output += text + "\n"
|
94
|
+
log_lambda.call(text) if !log_lambda.blank?
|
95
|
+
end
|
96
|
+
|
97
|
+
def log(text)
|
98
|
+
log_lambda.call(text) if !log_lambda.blank?
|
99
|
+
end
|
100
|
+
|
101
|
+
def send_status_email
|
102
|
+
MonitoredProcessMailer.process_execution_result_email(self).deliver
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.list(params)
|
106
|
+
parameters = []
|
107
|
+
parameters = params.clone if !params.blank?
|
108
|
+
conditions = []
|
109
|
+
|
110
|
+
if !params.blank?
|
111
|
+
if !params[:start_date].blank?
|
112
|
+
conditions << "created_at >= :start_date"
|
113
|
+
end
|
114
|
+
if !params[:end_date].blank?
|
115
|
+
conditions << "created_at <= :end_date"
|
116
|
+
end
|
117
|
+
if !params[:process_type].blank?
|
118
|
+
conditions << "name <= :process_type"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
parameters[:sort] = "id_desc" if params[:sort].blank?
|
123
|
+
|
124
|
+
where(conditions.join(" and "), parameters).sorted(parameters[:sort]).paginate(:page => parameters[:page], :per_page => 100)
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.translate_state(state)
|
128
|
+
case state
|
129
|
+
when STATE[:running]
|
130
|
+
"Running"
|
131
|
+
when STATE[:finished]
|
132
|
+
"Finished"
|
133
|
+
when STATE[:finished_with_errors]
|
134
|
+
"Finished with errors"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.get_process_names
|
139
|
+
MonitoredProcess.uniq.pluck(:name)
|
140
|
+
end
|
141
|
+
|
142
|
+
private
|
143
|
+
def set_finished_status
|
144
|
+
self.state = STATE[:finished]
|
145
|
+
self.calculate_elapsed_seconds
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|