Sha256: 42711be98a257894413cc818e8dfd486866ecbd6ce4c81c73bcd8df9a75a66d6

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module BatchManager
  class BatchesController < ApplicationController
    def index
      @details = BatchManager::Monitor.details
    end

    def exec
      @batch_name = params[:batch_name]
      @wet = params[:wet]
      if resque_supported?
        Resque.enqueue(BatchManager::ExecBatchWorker, @batch_name, :wet => @wet)
        @offset = log_file.size
      else
        BatchManager::Executor.exec(@batch_name, :wet => @wet)
        redirect_to(batches_url)
      end
    end

    def async_read_log
      file = log_file
      file.seek(params[:offset].to_i) if params[:offset].present?
      render :json => {:content => file.read, :offset => file.size}
    end

    def log
      log_file = BatchManager::Logger.log_file_path(params[:batch_name], params[:wet])
      render :file => log_file, :content_type => Mime::TEXT, :layout => false
    end

    private

    def resque_supported?
      begin
        require 'resque'
        defined?(Resque)
      rescue
        false
      end
    end

    def log_file
      File.open(BatchManager::Logger.log_file_path(params[:batch_name], params[:wet]), 'r')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
batch_manager-0.2.6 app/controllers/batch_manager/batches_controller.rb