batch_manager 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/app/controllers/batch_manager/application_controller.rb +25 -8
- data/app/controllers/batch_manager/batches_controller.rb +6 -3
- data/app/views/batch_manager/batches/index.html.erb +6 -2
- data/app/views/batch_manager/batches/log.html.erb +1 -1
- data/lib/batch_manager/executor.rb +29 -27
- data/lib/batch_manager/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzcyOGI4YjBhYTFjZmFjNGJhMWZiYTc4M2EyYmRiMjNmYjk0NTM1ZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDZlMDJjZjNiMDgwOTA2ZjYxMWQxM2NiOTM0NWI5ZmUyODZjZTNiOA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MGQ3Y2I4NDA4NmVjYWVhNTJiMGQ2MjJkYWM1Y2IzNmU3Y2ZiNDQyZjkyNmFh
|
10
|
+
OWE0ZjNkNDMyMjQzNjQ4NTdiMDkyNjYwOTE1YWFkMjE1YWEyZDNlNGFiZWY2
|
11
|
+
MDcwYTNjZDg1YmZlYjAyYjg4MDllZjQzMzMxNzc3ODkwOTk3NDM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGQxZmFhNjIzYjFhZWM5OGY4YmYyNDc1ZDk5NjI3ZDg2YjhlYzE3ZDk4MzBk
|
14
|
+
MjFkN2RmYTczNTJmZGNhZGFkZTAxODQ3MGNhOTY0MzAyYzQ4MGZiMTRhNDNl
|
15
|
+
Zjc0ZDI0NjcyZTczMWFhNDVmMDliYTU4NWIxMDdkZjI1YmFjMjQ=
|
@@ -1,19 +1,36 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
1
3
|
module BatchManager
|
2
4
|
class ApplicationController < ActionController::Base
|
5
|
+
helper_method :resque_supported?, :local_resque_worker?, :resque_worker_hostname
|
6
|
+
|
3
7
|
def resque_supported?
|
4
8
|
begin
|
5
9
|
require 'resque'
|
6
|
-
|
7
|
-
queue_names = []
|
8
|
-
Resque.workers.map do |worker|
|
9
|
-
queue_names += worker.id.split(':')[-1].split(',')
|
10
|
-
end
|
11
|
-
return true if queue_names.include?(BatchManager::ExecBatchWorker.queue_name) || queue_names.include?("*")
|
12
|
-
end
|
13
|
-
false
|
10
|
+
defined?(Resque) && resque_worker
|
14
11
|
rescue
|
15
12
|
false
|
16
13
|
end
|
17
14
|
end
|
15
|
+
|
16
|
+
def local_resque_worker?
|
17
|
+
Socket.gethostname == resque_worker_hostname
|
18
|
+
end
|
19
|
+
|
20
|
+
def resque_worker_hostname
|
21
|
+
resque_worker.id.split(':')[0]
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def resque_worker
|
27
|
+
@resque_worker ||= begin
|
28
|
+
workers = Resque.workers.select do |worker|
|
29
|
+
queue_names = worker.id.split(':')[-1].split(',')
|
30
|
+
queue_names.include?(BatchManager::ExecBatchWorker.queue_name) || queue_names.include?("*")
|
31
|
+
end
|
32
|
+
workers.first
|
33
|
+
end
|
34
|
+
end
|
18
35
|
end
|
19
36
|
end
|
@@ -7,7 +7,6 @@ module BatchManager
|
|
7
7
|
helper_method :escape_batch_name
|
8
8
|
|
9
9
|
def index
|
10
|
-
@resque_supported = resque_supported?
|
11
10
|
@details = BatchManager::Monitor.details
|
12
11
|
end
|
13
12
|
|
@@ -41,7 +40,11 @@ module BatchManager
|
|
41
40
|
def exec
|
42
41
|
if resque_supported?
|
43
42
|
Resque.enqueue(BatchManager::ExecBatchWorker, @batch_name, :wet => @wet)
|
44
|
-
|
43
|
+
if local_resque_worker?
|
44
|
+
redirect_to(log_batch_url(:batch_name => @batch_name, :wet => @wet, :refresh => true))
|
45
|
+
else
|
46
|
+
redirect_to(batches_url, :notice => "(#{@batch_name}) Task added to the remote resque worker.")
|
47
|
+
end
|
45
48
|
else
|
46
49
|
BatchManager::Executor.exec(@batch_name, :wet => @wet)
|
47
50
|
redirect_to(batches_url)
|
@@ -79,7 +82,7 @@ module BatchManager
|
|
79
82
|
end
|
80
83
|
|
81
84
|
def log_file
|
82
|
-
|
85
|
+
5.times do
|
83
86
|
begin
|
84
87
|
@log_file ||= File.open(BatchManager::Logger.log_file_path(@batch_name, @wet), 'r')
|
85
88
|
return @log_file
|
@@ -1,8 +1,12 @@
|
|
1
1
|
<div class="group title">
|
2
2
|
<h2 style="float:left;">Batches</h2>
|
3
3
|
<div style="float:right;text-align:right;">
|
4
|
-
<% if
|
5
|
-
|
4
|
+
<% if resque_supported? %>
|
5
|
+
<% if local_resque_worker? %>
|
6
|
+
<div class="label info">Resque worker found</div>
|
7
|
+
<% else %>
|
8
|
+
<div class="label info">Resque worker found on <%= resque_worker_hostname %></div>
|
9
|
+
<% end %>
|
6
10
|
<% else %>
|
7
11
|
<div class="label warn">Resque or Resque worker not found</div>
|
8
12
|
<% end %>
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<script>
|
3
3
|
function read_log() {
|
4
4
|
offset = $("#offset").val();
|
5
|
-
$.get('<%= async_read_log_batch_url(escape_batch_name(@batch_name), :wet => @wet) %>' + '&offset=' + offset, function(data) {
|
5
|
+
$.get('<%= async_read_log_batch_url(escape_batch_name(@batch_name), :wet => @wet, 1 => 1) %>' + '&offset=' + offset, function(data) {
|
6
6
|
$("#log_box").val($("#log_box").val() + data.content);
|
7
7
|
$("#offset").val(data.offset);
|
8
8
|
scrollLogBoxDown();
|
@@ -4,11 +4,12 @@ module BatchManager
|
|
4
4
|
|
5
5
|
class << self
|
6
6
|
def exec(batch_file, options = {})
|
7
|
-
batch_file_path = batch_full_path(batch_file)
|
8
|
-
if File.exist?(batch_file_path)
|
9
|
-
batch_status = BatchManager::BatchStatus.new(batch_file_path)
|
10
|
-
|
11
|
-
|
7
|
+
@batch_file_path = batch_full_path(batch_file)
|
8
|
+
if File.exist?(@batch_file_path)
|
9
|
+
@batch_status = BatchManager::BatchStatus.new(@batch_file_path)
|
10
|
+
@wet = options[:wet]
|
11
|
+
if options[:force] || !@wet || @batch_status.can_run?
|
12
|
+
record_run_duration { exec_batch_script }
|
12
13
|
else
|
13
14
|
raise "Cannot run this batch."
|
14
15
|
end
|
@@ -19,31 +20,32 @@ module BatchManager
|
|
19
20
|
|
20
21
|
protected
|
21
22
|
|
22
|
-
def
|
23
|
-
logger = BatchManager::Logger.new(batch_status.name,
|
24
|
-
write_log_header(is_wet)
|
23
|
+
def record_run_duration
|
24
|
+
@logger = BatchManager::Logger.new(@batch_status.name, @wet)
|
25
25
|
start_at = Time.now
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
26
|
+
yield
|
27
|
+
end_at = Time.now
|
28
|
+
@logger.info "End at: #{end_at.strftime("%Y-%m-%d %H:%M:%S")} (#{(end_at - start_at).to_i}s)"
|
29
|
+
@logger.close
|
30
|
+
end
|
31
|
+
|
32
|
+
def exec_batch_script
|
33
|
+
write_log_header
|
34
|
+
eval(File.read(@batch_file_path))
|
35
|
+
@logger.info "Succeeded."
|
36
|
+
@batch_status.update_schema if @wet
|
37
|
+
rescue => e
|
38
|
+
@logger.error e
|
39
|
+
@logger.info "Failed."
|
40
|
+
ensure
|
41
|
+
puts "Log saved at: #{@logger.log_file}" if @logger.log_file
|
40
42
|
end
|
41
43
|
|
42
|
-
def write_log_header
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
def write_log_header
|
45
|
+
@logger.info "=============================="
|
46
|
+
@logger.info "= #{@wet ? 'WET' : 'DRY'} RUN"
|
47
|
+
@logger.info "= Ran at: #{Time.now.strftime("%Y-%m-%d %H:%M:%S")}"
|
48
|
+
@logger.info "=============================="
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|