tasks_scheduler 0.6.13 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c54c9a9dba7d2601023944efb038902f7bd7d9f30a2eb922f10fa6575eb8e18
4
- data.tar.gz: 90b2bf8cf961dc20a175fcc064c04583a4eb5288af5779d7246c5c26d94ef986
3
+ metadata.gz: 8ac4a6905744856629c046c2cbca58290b37c32c1da3f4ef7558927247893ec2
4
+ data.tar.gz: 1cab19fa0a8be070731efa12f59c2d76cd1a293851b2d132324a60bf1c7d9fa0
5
5
  SHA512:
6
- metadata.gz: 8c6019296c5122948ae4f3f315e09fbb1da0527f76efc4fe05ffee4b89d1b60343b40c07795dda781ec30b61472215d3617e9f025f89c0a84707f73b547caf76
7
- data.tar.gz: 1c81e0019f50de3946129f858b6a146d0eed057bac8f00d67f8aa7835119442e202f79bdb5a7593fbec82797904ca44bc1a1d6b1bd6f119498ca0e483720c492
6
+ metadata.gz: 5028f905d36a4239fdcd137cc8fde66b2af61da61008871983a4f4bd0923063d904e1ece4f033037bbf29c697a7ce2a1ef44fd83b7f1e78125c590801408377f
7
+ data.tar.gz: 249dd1417fc904f03c6ae6a81fe17c8a7d6afb941c1ed09924ecfc71e926cc0e679f287d02bf62b7062279059bcc0915f263624320ffdec2deb67a1c01ea3c75
@@ -39,7 +39,7 @@ class ScheduledTasksController < ApplicationController
39
39
  process_action_link_action do |record|
40
40
  record.update!(next_run: Time.zone.now)
41
41
  record.reload
42
- flash[:info] = "Next run adjusted to #{record.next_run}"
42
+ flash.now[:info] = "Next run adjusted to #{record.next_run}"
43
43
  end
44
44
  end
45
45
  end
@@ -35,7 +35,7 @@ class TasksSchedulerDaemonController < ApplicationController
35
35
  send_file(
36
36
  log.path,
37
37
  filename: "#{request.base_url.parameterize}_tasks-scheduler_checker-log_" \
38
- "#{Time.zone.now.to_s.parameterize}.log",
38
+ "#{Time.zone.now.to_s.parameterize}.log",
39
39
  type: 'text/plain'
40
40
  )
41
41
  end
@@ -19,10 +19,10 @@ class ScheduledTask < ActiveRecord::Base
19
19
  def log_on_start
20
20
  log_file = log_file(LOG_RUNNING)
21
21
  FileUtils.mkdir_p(File.dirname(log_file))
22
- File.unlink(log_file) if File.exist?(log_file)
23
- STDOUT.reopen(log_file, 'w')
24
- STDERR.reopen(log_file, 'w')
25
- Rails.logger = ActiveSupport::Logger.new(STDOUT)
22
+ FileUtils.rm_f(log_file)
23
+ $stdout.reopen(log_file, 'w')
24
+ $stderr.reopen(log_file, 'w')
25
+ Rails.logger = ActiveSupport::Logger.new($stdout)
26
26
  end
27
27
 
28
28
  def log_on_end(exception)
@@ -30,7 +30,7 @@ class ScheduledTask < ActiveRecord::Base
30
30
  return unless ::File.exist?(running_log)
31
31
 
32
32
  target_log = exception ? log_file(LOG_UNSUCCESSFUL) : log_file(LOG_SUCCESSFUL)
33
- File.unlink(target_log) if File.exist?(target_log)
33
+ FileUtils.rm_f(target_log)
34
34
  File.rename(running_log, target_log)
35
35
  end
36
36
  end
@@ -22,7 +22,7 @@ class ScheduledTask < ActiveRecord::Base
22
22
 
23
23
  def timeout
24
24
  @timeout ||= begin
25
- r = Integer(ENV[DEFAULT_TIMEOUT_ENVVAR_NAME])
25
+ r = Integer(ENV.fetch(DEFAULT_TIMEOUT_ENVVAR_NAME, nil))
26
26
  r.positive? ? r.seconds : DEFAULT_TIMEOUT
27
27
  rescue ArgumentError, TypeError
28
28
  DEFAULT_TIMEOUT
@@ -1,4 +1,3 @@
1
- <%= tasks_scheduler_navbar %>
2
1
  <p>Log file: <%= @log_file %></p>
3
2
  <% if File.exist?(@log_file) %>
4
3
  <p>Content: </p>
@@ -1,4 +1,3 @@
1
- <%= tasks_scheduler_navbar %>
2
1
  <h2><%= I18n.t(:tasks_scheduler_status) %></h2>
3
2
  <div id="TaskScheduler_Status_Status">
4
3
  </div>
@@ -1,4 +1,3 @@
1
- <%= tasks_scheduler_navbar %>
2
1
  <h2><%= I18n.t(:tasks_scheduler_daemon) %></h2>
3
2
  <%= render partial: 'daemon', locals: {status_label: 'Status:'} %>
4
3
  <%= render partial: 'logs' %>
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_rails_utils/patches/application'
4
+
5
+ Rails.application.root_menu.group(:admin).group(:tasks_scheduler).within do |g|
6
+ g.action :tasks_scheduler_daemon
7
+ g.action :scheduled_tasks
8
+ g.action :status_scheduled_tasks
9
+ end
@@ -4,6 +4,15 @@ en:
4
4
  scheduled_task:
5
5
  one: Scheduled task
6
6
  other: Scheduled tasks
7
+ eac_rails_utils:
8
+ menus:
9
+ root:
10
+ admin:
11
+ tasks_scheduler:
12
+ __self: Tasks scheduler
13
+ main_app_tasks_scheduler_daemon: Daemon
14
+ main_app_scheduled_tasks: Tasks
15
+ main_app_status_scheduled_tasks: Status
7
16
  helpers:
8
17
  label:
9
18
  scheduled_task:
@@ -4,6 +4,15 @@ pt-BR:
4
4
  scheduled_task:
5
5
  one: Tarefa agendada
6
6
  other: Tarefas agendadas
7
+ eac_rails_utils:
8
+ menus:
9
+ root:
10
+ admin:
11
+ tasks_scheduler:
12
+ __self: 'Agendador de tarefas'
13
+ main_app_tasks_scheduler_daemon: Daemon
14
+ main_app_scheduled_tasks: Tarefas
15
+ main_app_status_scheduled_tasks: Situação
7
16
  helpers:
8
17
  label:
9
18
  scheduled_task:
data/exe/tasks_scheduler CHANGED
@@ -16,8 +16,8 @@ rails_root = find_rails_root
16
16
  dir = File.expand_path('tmp/pids', rails_root)
17
17
  FileUtils.mkdir_p(dir)
18
18
  Daemons.run_proc 'tasks_scheduler', dir_mode: :normal, dir: dir do
19
- ::Dir.chdir(rails_root) do
19
+ Dir.chdir(rails_root) do
20
20
  require File.join(rails_root, 'config', 'environment')
21
- ::TasksScheduler::Checker.instance.run
21
+ TasksScheduler::Checker.instance.run
22
22
  end
23
23
  end
@@ -13,4 +13,4 @@ end
13
13
 
14
14
  rails_root = find_rails_root
15
15
  require File.join(rails_root, 'config', 'environment')
16
- ::ScheduledTask.find(ARGV[0].to_i).run
16
+ ScheduledTask.find(ARGV[0].to_i).run
@@ -7,7 +7,7 @@ module TasksScheduler
7
7
  class Log
8
8
  class << self
9
9
  def logs_directory
10
- @logs_directory ||= ::Rails.root.join('log', 'tasks_scheduler', 'checker')
10
+ @logs_directory ||= ::Rails.root.join('log/tasks_scheduler/checker')
11
11
  end
12
12
  end
13
13
 
@@ -16,7 +16,7 @@ module TasksScheduler
16
16
  Signal.trap('TERM') { running = false }
17
17
  while running
18
18
  Rails.logger.info('Checking all tasks...')
19
- ::ScheduledTask.all.order(next_run: :asc).each(&:check)
19
+ ::ScheduledTask.order(next_run: :asc).each(&:check)
20
20
  Rails.logger.info("All tasks checked. Sleeping for #{CHECK_INTERVAL} second(s)...")
21
21
  sleep(CHECK_INTERVAL)
22
22
  end
@@ -31,7 +31,7 @@ module TasksScheduler
31
31
  end
32
32
 
33
33
  LOGS_KEYS.each do |log_key|
34
- class_eval <<CODE, __FILE__, __LINE__ + 1
34
+ class_eval <<CODE, __FILE__, __LINE__ + 1 # rubocop:disable Style/DocumentDynamicEvalDefinition
35
35
  def #{log_key}_log
36
36
  @#{log_key}_log ||= ::TasksScheduler::Checker::Log.new('#{log_key}')
37
37
  end
@@ -26,6 +26,6 @@ module TasksScheduler
26
26
  end
27
27
  end
28
28
 
29
- unless ::CronParser.included_modules.include?(::TasksScheduler::CronParserPatch)
30
- ::CronParser.include(::TasksScheduler::CronParserPatch)
29
+ unless CronParser.included_modules.include?(TasksScheduler::CronParserPatch)
30
+ CronParser.include(TasksScheduler::CronParserPatch)
31
31
  end
@@ -5,8 +5,8 @@ module TasksScheduler
5
5
  def validate_each(record, attribute, value)
6
6
  return if value_valid?(value)
7
7
 
8
- record.errors[attribute] << (options[:message] ||
9
- I18n.t(:cron_scheduling_validator_error_message))
8
+ record.errors.add(attribute, (options[:message] ||
9
+ I18n.t(:cron_scheduling_validator_error_message)))
10
10
  end
11
11
 
12
12
  private
@@ -1,13 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_active_scaffold'
4
+ require 'eac_rails_utils/engine'
5
+ require 'eac_rails_utils/engine_helper'
4
6
 
5
7
  module TasksScheduler
6
8
  class Engine < ::Rails::Engine
7
- initializer :append_migrations do |app|
8
- config.paths['db/migrate'].expanded.each do |expanded_path|
9
- app.config.paths['db/migrate'] << expanded_path
10
- end
11
- end
9
+ include ::EacRailsUtils::EngineHelper
12
10
  end
13
11
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TasksScheduler
4
- VERSION = '0.6.13'
4
+ VERSION = '0.8.0'
5
5
  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.6.13
4
+ version: 0.8.0
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: 2023-09-14 00:00:00.000000000 Z
11
+ date: 2023-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avm-eac_ruby_base1
@@ -76,14 +76,14 @@ dependencies:
76
76
  requirements:
77
77
  - - "~>"
78
78
  - !ruby/object:Gem::Version
79
- version: '0.21'
79
+ version: '0.22'
80
80
  type: :runtime
81
81
  prerelease: false
82
82
  version_requirements: !ruby/object:Gem::Requirement
83
83
  requirements:
84
84
  - - "~>"
85
85
  - !ruby/object:Gem::Version
86
- version: '0.21'
86
+ version: '0.22'
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: eac_ruby_utils
89
89
  requirement: !ruby/object:Gem::Requirement
@@ -144,20 +144,14 @@ dependencies:
144
144
  requirements:
145
145
  - - "~>"
146
146
  - !ruby/object:Gem::Version
147
- version: '0.4'
148
- - - ">="
149
- - !ruby/object:Gem::Version
150
- version: 0.4.1
147
+ version: 0.8.0
151
148
  type: :development
152
149
  prerelease: false
153
150
  version_requirements: !ruby/object:Gem::Requirement
154
151
  requirements:
155
152
  - - "~>"
156
153
  - !ruby/object:Gem::Version
157
- version: '0.4'
158
- - - ">="
159
- - !ruby/object:Gem::Version
160
- version: 0.4.1
154
+ version: 0.8.0
161
155
  description:
162
156
  email:
163
157
  - eduardobogoni@gmail.com
@@ -179,13 +173,11 @@ files:
179
173
  - app/controllers/tasks_scheduler_daemon_controller.rb
180
174
  - app/controllers/tasks_scheduler_daemon_controller/_download_log.rb
181
175
  - app/helpers/scheduled_tasks_helper.rb
182
- - app/helpers/tasks_scheduler_helper.rb
183
176
  - app/models/scheduled_task.rb
184
177
  - app/models/scheduled_task/checker.rb
185
178
  - app/models/scheduled_task/log.rb
186
179
  - app/models/scheduled_task/runner.rb
187
180
  - app/models/scheduled_task/status.rb
188
- - app/views/scheduled_tasks/list.html.erb
189
181
  - app/views/scheduled_tasks/log.html.erb
190
182
  - app/views/scheduled_tasks/status.html.erb
191
183
  - app/views/scheduled_tasks/status_content.html.erb
@@ -196,6 +188,7 @@ files:
196
188
  - app/views/tasks_scheduler_daemon/_running_status.html.erb
197
189
  - app/views/tasks_scheduler_daemon/index.html.erb
198
190
  - config/initializers/assets.rb
191
+ - config/initializers/menus.rb
199
192
  - config/locales/en.yml
200
193
  - config/locales/pt-BR.yml
201
194
  - config/routes.rb
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module TasksSchedulerHelper
4
- NAVBAR_ENTRIES = {
5
- tasks_scheduler_daemon: 'tasks_scheduler_daemon',
6
- scheduled_tasks: 'scheduled_tasks',
7
- tasks_scheduler_status: :status_scheduled_tasks
8
- }.freeze
9
-
10
- def tasks_scheduler_navbar
11
- tag.navbar do
12
- safe_join(tasks_scheduler_navbar_entries.map { |label, path| link_to label, path }, ' | ')
13
- end
14
- end
15
-
16
- def tasks_scheduler_navbar_entries
17
- NAVBAR_ENTRIES
18
- .map { |i18n_key, path_name| [::I18n.t(i18n_key), send("#{path_name}_path")] }
19
- .to_h
20
- end
21
- end
@@ -1,2 +0,0 @@
1
- <%= tasks_scheduler_navbar %>
2
- <%= render :super %>