Sha256: 06c89acf089fde6099516e158e72c35f26116f8ab93887b9e9618a4304721aa9

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

class TasksSchedulerDaemonController < ApplicationController
  def download_log
    return unless download_log_validate_log_key

    log = ::TasksScheduler::Checker.instance.send("#{download_log_key}_log")
    return unless download_log_validate_log_exist(log)

    send_log_file(log)
  end

  private

  def download_log_key
    params[:log_key]
  end

  def download_log_validate_log_key
    return true if ::TasksScheduler::Checker::LOGS_KEYS.include?(download_log_key)

    redirect_to(tasks_scheduler_daemon_path,
                notice: "Invalid log key: \"#{download_log_key}\"")
    false
  end

  def download_log_validate_log_exist(log)
    return true if log.exist?

    redirect_to(tasks_scheduler_daemon_path, notice: "Log \"#{log.key}\" does not exist.")
    false
  end

  def send_log_file(log)
    send_file(
      log.path,
      filename: "#{request.base_url.parameterize}_tasks-scheduler_checker-log_" \
                "#{Time.zone.now.to_s.parameterize}.log",
      type: 'text/plain'
    )
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tasks_scheduler-0.9.4 app/controllers/tasks_scheduler_daemon_controller/_download_log.rb
tasks_scheduler-0.9.3 app/controllers/tasks_scheduler_daemon_controller/_download_log.rb
tasks_scheduler-0.9.2 app/controllers/tasks_scheduler_daemon_controller/_download_log.rb
tasks_scheduler-0.9.1 app/controllers/tasks_scheduler_daemon_controller/_download_log.rb
tasks_scheduler-0.9.0 app/controllers/tasks_scheduler_daemon_controller/_download_log.rb
tasks_scheduler-0.8.0 app/controllers/tasks_scheduler_daemon_controller/_download_log.rb