tasks_scheduler 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/tasks_scheduler_daemon_controller.rb +20 -0
- data/app/views/tasks_scheduler_daemon/index.html.erb +3 -0
- data/config/routes.rb +2 -0
- data/lib/tasks_scheduler/checker.rb +19 -3
- data/lib/tasks_scheduler/daemon.rb +4 -10
- data/lib/tasks_scheduler/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 48b30c798060f58365bfc12beb93db3972b529d9
         | 
| 4 | 
            +
              data.tar.gz: 2b875abb3eb4984f7a3a59590a0911c5cefb48fc
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: f7a07ad30c4510c9318231162c5c1f785ba398ab141e3bca282cac4d7560eca290aa450f1e7d4c181775679587637af36d1e3b0b56ed44d18005cb6304e15d93
         | 
| 7 | 
            +
              data.tar.gz: 205d290aef278c20bfa4e57ec279f00ab7d54ff7ded576d8b23221e0aedb87c079175e8fbca9b8391e9e2bdb1d74cd320881f46e5796da6048b81ec6fed05863
         | 
| @@ -10,4 +10,24 @@ class TasksSchedulerDaemonController < ApplicationController | |
| 10 10 | 
             
              def running
         | 
| 11 11 | 
             
                render plain: (::TasksScheduler::Daemon.running? ? 'true' : 'false'), layout: false
         | 
| 12 12 | 
             
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              def download_log
         | 
| 15 | 
            +
                if File.exist?(::TasksScheduler::Checker.instance.log_path)
         | 
| 16 | 
            +
                  send_log_file
         | 
| 17 | 
            +
                else
         | 
| 18 | 
            +
                  redirect_to(tasks_scheduler_daemon_path,
         | 
| 19 | 
            +
                              notice: "Arquivo \"#{::TasksScheduler::Checker.instance.log_path}\" não existe")
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              private
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              def send_log_file
         | 
| 26 | 
            +
                send_file(
         | 
| 27 | 
            +
                  ::TasksScheduler::Checker.instance.log_path,
         | 
| 28 | 
            +
                  filename: "#{request.base_url.parameterize}_tasks-scheduler_checker-log_" \
         | 
| 29 | 
            +
                    "#{Time.zone.now.to_s.parameterize}.log",
         | 
| 30 | 
            +
                  type: 'text/plain'
         | 
| 31 | 
            +
                )
         | 
| 32 | 
            +
              end
         | 
| 13 33 | 
             
            end
         | 
| @@ -7,6 +7,9 @@ | |
| 7 7 | 
             
              <%= safe_join(::TasksScheduler::Daemon::ACTIONS.map do |action|
         | 
| 8 8 | 
             
                  link_to action, execute_tasks_scheduler_daemon_path(action), method: :post
         | 
| 9 9 | 
             
                end, ' | ') %>
         | 
| 10 | 
            +
              <br/>
         | 
| 11 | 
            +
              <strong>Log: </strong>
         | 
| 12 | 
            +
              <%= link_to 'download', download_log_tasks_scheduler_daemon_path %>
         | 
| 10 13 | 
             
            </p>
         | 
| 11 14 | 
             
            <% if @result %>
         | 
| 12 15 | 
             
              <h3>Results</h3>
         | 
    
        data/config/routes.rb
    CHANGED
    
    | @@ -15,4 +15,6 @@ Rails.application.routes.draw do | |
| 15 15 | 
             
                   to: 'tasks_scheduler_daemon#execute', as: :execute_tasks_scheduler_daemon
         | 
| 16 16 | 
             
              get '/tasks_scheduler_daemon/running', to: 'tasks_scheduler_daemon#running',
         | 
| 17 17 | 
             
                                                     as: :running_tasks_scheduler_daemon
         | 
| 18 | 
            +
              get '/tasks_scheduler_daemon/download_log', to: 'tasks_scheduler_daemon#download_log',
         | 
| 19 | 
            +
                                                          as: :download_log_tasks_scheduler_daemon
         | 
| 18 20 | 
             
            end
         | 
| @@ -3,12 +3,12 @@ module TasksScheduler | |
| 3 3 | 
             
                include Singleton
         | 
| 4 4 |  | 
| 5 5 | 
             
                CHECK_INTERVAL = 15
         | 
| 6 | 
            +
                LOG_ON_FILE_ENV_KEY = 'TASKS_SCHEDULER_LOG_ON_FILE'.freeze
         | 
| 6 7 |  | 
| 7 8 | 
             
                def run
         | 
| 9 | 
            +
                  check_log
         | 
| 8 10 | 
             
                  running = true
         | 
| 9 | 
            -
                  Signal.trap('TERM')  | 
| 10 | 
            -
                    running = false
         | 
| 11 | 
            -
                  end
         | 
| 11 | 
            +
                  Signal.trap('TERM') { running = false }
         | 
| 12 12 | 
             
                  while running
         | 
| 13 13 | 
             
                    Rails.logger.info('Checking all tasks...')
         | 
| 14 14 | 
             
                    ::ScheduledTask.all.each(&:check)
         | 
| @@ -16,5 +16,21 @@ module TasksScheduler | |
| 16 16 | 
             
                    sleep(CHECK_INTERVAL)
         | 
| 17 17 | 
             
                  end
         | 
| 18 18 | 
             
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def log_path
         | 
| 21 | 
            +
                  ::Rails.root.join('log', 'tasks_scheduler', 'checker.log')
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                private
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                def check_log
         | 
| 27 | 
            +
                  return unless log_on_file?
         | 
| 28 | 
            +
                  ::FileUtils.mkdir_p(File.dirname(log_path))
         | 
| 29 | 
            +
                  ::Rails.logger = ::Logger.new(log_path)
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                def log_on_file?
         | 
| 33 | 
            +
                  ENV[LOG_ON_FILE_ENV_KEY].present?
         | 
| 34 | 
            +
                end
         | 
| 19 35 | 
             
              end
         | 
| 20 36 | 
             
            end
         | 
| @@ -5,19 +5,9 @@ module TasksScheduler | |
| 5 5 | 
             
                ACTIONS = %w(status start stop restart).freeze
         | 
| 6 6 |  | 
| 7 7 | 
             
                class << self
         | 
| 8 | 
            -
                  def run(rails_root)
         | 
| 9 | 
            -
                    dir = File.expand_path('tmp/pids', rails_root)
         | 
| 10 | 
            -
                    FileUtils.mkdir_p(dir)
         | 
| 11 | 
            -
                    Daemons.run_proc 'tasks_scheduler', dir_mode: :normal, dir: dir do
         | 
| 12 | 
            -
                      require File.join(rails_root, 'config', 'environment')
         | 
| 13 | 
            -
                      ::TasksScheduler::Checker.instance.run
         | 
| 14 | 
            -
                    end
         | 
| 15 | 
            -
                  end
         | 
| 16 | 
            -
             | 
| 17 8 | 
             
                  def execute(action)
         | 
| 18 9 | 
             
                    raise "Action not allowed: #{action} (Allowed: #{ACTIONS})" unless ACTIONS.include?(action)
         | 
| 19 10 | 
             
                    command = ['bundle', 'exec', 'tasks_scheduler', action]
         | 
| 20 | 
            -
                    env_args = { 'RAILS_ENV' => Rails.env }
         | 
| 21 11 | 
             
                    Dir.chdir(Rails.root) do
         | 
| 22 12 | 
             
                      Open3.popen3(env_args, *command) do |_stdin, stdout, stderr, wait_thr|
         | 
| 23 13 | 
             
                        { action: action, env_args: env_args.map { |k, v| "#{k}=#{v}" }.join(' | '),
         | 
| @@ -30,6 +20,10 @@ module TasksScheduler | |
| 30 20 | 
             
                  def running?
         | 
| 31 21 | 
             
                    execute('status')[:status].zero?
         | 
| 32 22 | 
             
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  def env_args
         | 
| 25 | 
            +
                    { 'RAILS_ENV' => Rails.env, ::TasksScheduler::Checker::LOG_ON_FILE_ENV_KEY => '1' }
         | 
| 26 | 
            +
                  end
         | 
| 33 27 | 
             
                end
         | 
| 34 28 | 
             
              end
         | 
| 35 29 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: tasks_scheduler
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.7
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Eduardo H. Bogoni
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2018-01-05 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: active_scaffold
         |