Class: BatchManager::BatchesController
Instance Method Summary
collapse
Methods included from Utils
included
#local_resque_worker?, #resque_supported?, #resque_worker_hostname
Instance Method Details
#async_read_log ⇒ Object
59
60
61
62
|
# File 'app/controllers/batch_manager/batches_controller.rb', line 59
def async_read_log
log_file.seek(params[:offset].to_i) if params[:offset].present?
render :json => {:content => log_file.read, :offset => log_file.size}
end
|
#create ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'app/controllers/batch_manager/batches_controller.rb', line 18
def create
batch_name = params[:batch_name]
if batch_name.blank?
flash[:error] = "Please input the batch name."
redirect_to(new_batch_url) and return
end
file_path = File.join(BatchManager.batch_dir, batch_name)
file_path << ".rb" unless file_path.end_with?(".rb")
FileUtils.mkdir_p(File.dirname(file_path)) if batch_name.include?("/")
File.open(file_path, "w") { |f| f << params[:content] }
redirect_to(batches_url, :notice => "#{batch_name} created.")
end
|
#edit ⇒ Object
31
32
33
|
# File 'app/controllers/batch_manager/batches_controller.rb', line 31
def edit
@content = File.read(batch_full_path(@batch_name))
end
|
#escape_batch_name(name) ⇒ Object
69
70
71
|
# File 'app/controllers/batch_manager/batches_controller.rb', line 69
def escape_batch_name(name)
name.gsub("/", "|")
end
|
#exec ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'app/controllers/batch_manager/batches_controller.rb', line 40
def exec
if resque_supported?
Resque.enqueue(BatchManager::ExecBatchWorker, @batch_name, :wet => @wet)
if local_resque_worker?
redirect_to(log_batch_url(:batch_name => @batch_name, :wet => @wet, :refresh => true))
else
redirect_to(batches_url, :notice => "(#{@batch_name}) Task added to the remote resque worker.")
end
else
BatchManager::Executor.exec(@batch_name, :wet => @wet)
redirect_to(batches_url)
end
end
|
#index ⇒ Object
9
10
11
|
# File 'app/controllers/batch_manager/batches_controller.rb', line 9
def index
@details = BatchManager::Monitor.details
end
|
#log ⇒ Object
54
55
56
57
|
# File 'app/controllers/batch_manager/batches_controller.rb', line 54
def log
@offset = log_file.size
@content = log_file.read
end
|
#new ⇒ Object
13
14
15
16
|
# File 'app/controllers/batch_manager/batches_controller.rb', line 13
def new
template = File.read(File.join(Rails::Generators::BatchGenerator.source_root, "batch.rb"))
@content = ERB.new(template).result(binding)
end
|
#remove_log ⇒ Object
64
65
66
67
|
# File 'app/controllers/batch_manager/batches_controller.rb', line 64
def remove_log
FileUtils.rm(BatchManager::Logger.log_file_path(@batch_name, @wet))
redirect_to(batches_url, :notice => "Log removed.")
end
|
#unescape_batch_name(name) ⇒ Object
73
74
75
|
# File 'app/controllers/batch_manager/batches_controller.rb', line 73
def unescape_batch_name(name)
name.gsub("|", "/")
end
|
#update ⇒ Object
35
36
37
38
|
# File 'app/controllers/batch_manager/batches_controller.rb', line 35
def update
File.open(batch_full_path(@batch_name), "w") { |f| f << params[:content] }
redirect_to(batches_url, :notice => "#{@batch_name} updated.")
end
|