tasks_scheduler 0.3.0 → 0.4.0
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/Rakefile +3 -1
- data/app/controllers/scheduled_tasks_controller.rb +5 -4
- data/app/controllers/tasks_scheduler_daemon_controller.rb +4 -3
- data/app/controllers/tasks_scheduler_daemon_controller/_download_log.rb +6 -0
- data/app/helpers/scheduled_tasks_helper.rb +2 -0
- data/app/models/scheduled_task.rb +12 -8
- data/app/models/scheduled_task/checker.rb +5 -2
- data/app/models/scheduled_task/log.rb +9 -6
- data/app/models/scheduled_task/runner.rb +9 -5
- data/app/models/scheduled_task/status.rb +8 -4
- data/config/initializers/assets.rb +3 -1
- data/config/routes.rb +2 -0
- data/db/migrate/20161122123828_create_scheduled_tasks.rb +2 -0
- data/db/migrate/20161123130153_add_status_attributes_to_scheduled_tasks.rb +2 -0
- data/db/migrate/20161124200712_add_pid_to_scheduled_tasks.rb +2 -0
- data/db/migrate/20161128163702_add_args_to_scheduled_tasks.rb +2 -0
- data/db/migrate/20180223155025_add_last_fail_status_to_scheduled_tasks.rb +2 -0
- data/db/migrate/20180302170138_add_enabled_to_scheduled_tasks.rb +2 -0
- data/exe/tasks_scheduler +3 -1
- data/exe/tasks_scheduler_run_task +3 -1
- data/lib/tasks_scheduler.rb +2 -0
- data/lib/tasks_scheduler/checker.rb +5 -2
- data/lib/tasks_scheduler/checker/log.rb +2 -0
- data/lib/tasks_scheduler/cron_parser_patch.rb +3 -1
- data/lib/tasks_scheduler/cron_scheduling_validator.rb +3 -0
- data/lib/tasks_scheduler/daemon.rb +4 -1
- data/lib/tasks_scheduler/engine.rb +2 -0
- data/lib/tasks_scheduler/version.rb +3 -1
- data/test/dummy/Rakefile +3 -1
- data/test/dummy/app/controllers/application_controller.rb +2 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/bin/bundle +3 -1
- data/test/dummy/bin/rails +3 -1
- data/test/dummy/bin/rake +2 -0
- data/test/dummy/bin/setup +3 -1
- data/test/dummy/config.ru +2 -0
- data/test/dummy/config/application.rb +3 -1
- data/test/dummy/config/boot.rb +4 -2
- data/test/dummy/config/environment.rb +3 -1
- data/test/dummy/config/environments/development.rb +2 -0
- data/test/dummy/config/environments/production.rb +2 -0
- data/test/dummy/config/environments/test.rb +2 -0
- data/test/dummy/config/initializers/assets.rb +2 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +1 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +2 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +2 -0
- data/test/dummy/config/initializers/inflections.rb +1 -0
- data/test/dummy/config/initializers/mime_types.rb +1 -0
- data/test/dummy/config/initializers/session_store.rb +2 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +2 -0
- data/test/dummy/config/routes.rb +2 -0
- data/test/models/scheduled_task_test.rb +6 -4
- data/test/test_helper.rb +6 -4
- metadata +26 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6573b654529a255fe7a822f33662837da3915a7b9a98cdc6e071c19d3143c955
|
4
|
+
data.tar.gz: 3409022b969859d61f236ed5ddbf1678105ef35bd2cd971d5a172c56c43822b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e93580d187fd4e4ff62faf5ee5b5b0b5ea70b13b11f86f38779327f2bb06f329e46089b3add379cc734a06fd666c7a9edc40156939abc8ffadeb655bd43c6f22
|
7
|
+
data.tar.gz: cf55f3658eb3df0c1527a219b67a03ce401af2ce22dde55e49b90184b4c4019c21bd2ab0fc3e3a7741cf6a70e4f2ca8c8a8ec6578b3d304bf6efb62ee5c4c079
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
begin
|
2
4
|
require 'bundler/setup'
|
3
5
|
rescue LoadError
|
@@ -14,7 +16,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
14
16
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
17
|
end
|
16
18
|
|
17
|
-
APP_RAKEFILE = File.expand_path('
|
19
|
+
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
|
18
20
|
load 'rails/tasks/engine.rake'
|
19
21
|
|
20
22
|
load 'rails/tasks/statistics.rake'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ScheduledTasksController < ApplicationController
|
2
4
|
class << self
|
3
5
|
private
|
@@ -8,7 +10,7 @@ class ScheduledTasksController < ApplicationController
|
|
8
10
|
end
|
9
11
|
|
10
12
|
active_scaffold :scheduled_task do |conf|
|
11
|
-
[
|
13
|
+
%i[create update list].each do |action|
|
12
14
|
conf.send(action).columns.exclude(:next_run, :last_fail_status, :last_run_start,
|
13
15
|
:last_run_successful_start, :last_run_unsuccessful_start,
|
14
16
|
:last_run_successful_end, :last_run_unsuccessful_end,
|
@@ -26,8 +28,7 @@ class ScheduledTasksController < ApplicationController
|
|
26
28
|
@log_file = record.log_file(params[:identifier])
|
27
29
|
end
|
28
30
|
|
29
|
-
def status
|
30
|
-
end
|
31
|
+
def status; end
|
31
32
|
|
32
33
|
def status_content
|
33
34
|
@scheduled_tasks = ::ScheduledTask.order(task: :asc, scheduling: :asc)
|
@@ -36,7 +37,7 @@ class ScheduledTasksController < ApplicationController
|
|
36
37
|
|
37
38
|
def run_now
|
38
39
|
process_action_link_action do |record|
|
39
|
-
record.
|
40
|
+
record.update!(next_run: Time.zone.now)
|
40
41
|
record.reload
|
41
42
|
flash[:info] = "Next run adjusted to #{record.next_run}"
|
42
43
|
end
|
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'tasks_scheduler/checker'
|
2
4
|
|
3
5
|
class TasksSchedulerDaemonController < ApplicationController
|
4
6
|
require_relative 'tasks_scheduler_daemon_controller/_download_log'
|
5
7
|
|
6
|
-
def index
|
7
|
-
end
|
8
|
+
def index; end
|
8
9
|
|
9
10
|
def execute
|
10
11
|
@result = ::TasksScheduler::Daemon.execute(params[:tasks_scheduler_execute_action])
|
@@ -13,6 +14,6 @@ class TasksSchedulerDaemonController < ApplicationController
|
|
13
14
|
|
14
15
|
def status
|
15
16
|
render json: { daemon_running: ::TasksScheduler::Daemon.running?,
|
16
|
-
tasks_all_ok:
|
17
|
+
tasks_all_ok: ::ScheduledTask.all.none?(&:failed?) }
|
17
18
|
end
|
18
19
|
end
|
@@ -1,8 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class TasksSchedulerDaemonController < ApplicationController
|
2
4
|
def download_log
|
3
5
|
return unless download_log_validate_log_key
|
6
|
+
|
4
7
|
log = ::TasksScheduler::Checker.instance.send("#{download_log_key}_log")
|
5
8
|
return unless download_log_validate_log_exist(log)
|
9
|
+
|
6
10
|
send_log_file(log)
|
7
11
|
end
|
8
12
|
|
@@ -14,6 +18,7 @@ class TasksSchedulerDaemonController < ApplicationController
|
|
14
18
|
|
15
19
|
def download_log_validate_log_key
|
16
20
|
return true if ::TasksScheduler::Checker::LOGS_KEYS.include?(download_log_key)
|
21
|
+
|
17
22
|
redirect_to(tasks_scheduler_daemon_path,
|
18
23
|
notice: "Invalid log key: \"#{download_log_key}\"")
|
19
24
|
false
|
@@ -21,6 +26,7 @@ class TasksSchedulerDaemonController < ApplicationController
|
|
21
26
|
|
22
27
|
def download_log_validate_log_exist(log)
|
23
28
|
return true if log.exist?
|
29
|
+
|
24
30
|
redirect_to(tasks_scheduler_daemon_path, notice: "Log \"#{log.key}\" does not exist.")
|
25
31
|
false
|
26
32
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rake'
|
2
4
|
|
3
5
|
class ScheduledTask < ActiveRecord::Base
|
@@ -6,7 +8,7 @@ class ScheduledTask < ActiveRecord::Base
|
|
6
8
|
include ::ScheduledTask::Runner
|
7
9
|
include ::ScheduledTask::Status
|
8
10
|
|
9
|
-
DEFAULT_TIMEOUT_ENVVAR_NAME = 'TASKS_SCHEDULER_TIMEOUT'
|
11
|
+
DEFAULT_TIMEOUT_ENVVAR_NAME = 'TASKS_SCHEDULER_TIMEOUT'
|
10
12
|
DEFAULT_TIMEOUT = 12.hours
|
11
13
|
|
12
14
|
class << self
|
@@ -20,9 +22,9 @@ class ScheduledTask < ActiveRecord::Base
|
|
20
22
|
def timeout
|
21
23
|
@timeout ||= begin
|
22
24
|
r = Integer(ENV[DEFAULT_TIMEOUT_ENVVAR_NAME])
|
23
|
-
r
|
24
|
-
|
25
|
-
|
25
|
+
r.positive? ? r.seconds : DEFAULT_TIMEOUT
|
26
|
+
rescue ArgumentError, TypeError
|
27
|
+
DEFAULT_TIMEOUT
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
@@ -34,7 +36,7 @@ class ScheduledTask < ActiveRecord::Base
|
|
34
36
|
STATUS_TIMEOUT = 'timeout'
|
35
37
|
STATUS_DISABLED = 'disabled'
|
36
38
|
|
37
|
-
LAST_FAIL_STATUSES = [STATUS_FAILED, STATUS_ABORTED, STATUS_TIMEOUT]
|
39
|
+
LAST_FAIL_STATUSES = [STATUS_FAILED, STATUS_ABORTED, STATUS_TIMEOUT].freeze
|
38
40
|
|
39
41
|
validates :scheduling, presence: true, 'tasks_scheduler/cron_scheduling': true
|
40
42
|
validates :task, presence: true
|
@@ -69,13 +71,14 @@ class ScheduledTask < ActiveRecord::Base
|
|
69
71
|
|
70
72
|
def process_running?
|
71
73
|
return false if pid.nil?
|
74
|
+
|
72
75
|
Process.kill(0, pid)
|
73
|
-
|
76
|
+
true
|
74
77
|
rescue Errno::EPERM
|
75
78
|
raise "No permission to query #{pid}!"
|
76
79
|
rescue Errno::ESRCH
|
77
|
-
|
78
|
-
rescue
|
80
|
+
false
|
81
|
+
rescue StandardError
|
79
82
|
raise "Unable to determine status for #{pid}"
|
80
83
|
end
|
81
84
|
|
@@ -87,6 +90,7 @@ class ScheduledTask < ActiveRecord::Base
|
|
87
90
|
return if task.blank?
|
88
91
|
return unless task_changed?
|
89
92
|
return if self.class.rake_tasks.include?(task)
|
93
|
+
|
90
94
|
errors.add(:task, "Task \"#{task}\" not found")
|
91
95
|
end
|
92
96
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rake'
|
2
4
|
|
3
5
|
class ScheduledTask < ActiveRecord::Base
|
@@ -34,6 +36,7 @@ class ScheduledTask < ActiveRecord::Base
|
|
34
36
|
|
35
37
|
def check_on_pid_not_present
|
36
38
|
return unless enabled?
|
39
|
+
|
37
40
|
if next_run.present?
|
38
41
|
check_task_with_next_run
|
39
42
|
else
|
@@ -55,7 +58,7 @@ class ScheduledTask < ActiveRecord::Base
|
|
55
58
|
|
56
59
|
def check_task_without_next_run
|
57
60
|
check_log('Next run blank')
|
58
|
-
|
61
|
+
update!(next_run: calculate_next_run)
|
59
62
|
check_log("Next run scheduled: #{next_run.in_time_zone}")
|
60
63
|
end
|
61
64
|
|
@@ -78,7 +81,7 @@ class ScheduledTask < ActiveRecord::Base
|
|
78
81
|
spawn_pid = Process.spawn(*params)
|
79
82
|
end
|
80
83
|
Process.detach(spawn_pid)
|
81
|
-
|
84
|
+
update!(pid: spawn_pid, last_fail_status: nil)
|
82
85
|
end
|
83
86
|
|
84
87
|
def timeout?
|
@@ -1,9 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ScheduledTask < ActiveRecord::Base
|
2
4
|
module Log
|
3
5
|
def log_file(identifier)
|
4
6
|
unless log_identifiers.include?(identifier)
|
5
|
-
|
7
|
+
raise "Log identifier unknown: \"#{identifier}\" (Valid: #{log_identifiers})"
|
6
8
|
end
|
9
|
+
|
7
10
|
Rails.root.join('log', 'tasks_scheduler', "#{id}_#{identifier}.log")
|
8
11
|
end
|
9
12
|
|
@@ -24,11 +27,11 @@ class ScheduledTask < ActiveRecord::Base
|
|
24
27
|
|
25
28
|
def log_on_end(exception)
|
26
29
|
running_log = log_file(LOG_RUNNING)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
return unless ::File.exist?(running_log)
|
31
|
+
|
32
|
+
target_log = exception ? log_file(LOG_UNSUCCESSFUL) : log_file(LOG_SUCCESSFUL)
|
33
|
+
File.unlink(target_log) if File.exist?(target_log)
|
34
|
+
File.rename(running_log, target_log)
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
@@ -1,9 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ScheduledTask < ActiveRecord::Base
|
2
4
|
module Runner
|
3
5
|
def run
|
4
6
|
log_on_start
|
5
7
|
run_banner
|
6
8
|
return if process_running? && pid != Process.pid
|
9
|
+
|
7
10
|
status_on_start
|
8
11
|
exception = invoke_task
|
9
12
|
on_end_running(exception, STATUS_FAILED)
|
@@ -33,7 +36,7 @@ class ScheduledTask < ActiveRecord::Base
|
|
33
36
|
|
34
37
|
def run_banner
|
35
38
|
run_log("Task: #{self}")
|
36
|
-
run_log("PID: #{pid
|
39
|
+
run_log("PID: #{pid || '-'} (Current: #{Process.pid})")
|
37
40
|
run_log("Process running? #{process_running? ? 'Yes' : 'No'}")
|
38
41
|
run_log("Rails.env: #{Rails.env}")
|
39
42
|
end
|
@@ -44,15 +47,16 @@ class ScheduledTask < ActiveRecord::Base
|
|
44
47
|
Rake::Task.clear
|
45
48
|
Rails.application.load_tasks
|
46
49
|
Rake::Task[task].invoke(*invoke_args)
|
47
|
-
rescue StandardError =>
|
48
|
-
run_log(
|
49
|
-
exception =
|
50
|
+
rescue StandardError => e
|
51
|
+
run_log(e, :fatal)
|
52
|
+
exception = e
|
50
53
|
end
|
51
54
|
exception
|
52
55
|
end
|
53
56
|
|
54
57
|
def invoke_args
|
55
|
-
return []
|
58
|
+
return [] if args.blank?
|
59
|
+
|
56
60
|
args.split('|')
|
57
61
|
end
|
58
62
|
end
|
@@ -1,10 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ScheduledTask < ActiveRecord::Base
|
2
4
|
module Status
|
3
5
|
def status
|
4
6
|
return STATUS_DISABLED unless enabled?
|
5
7
|
return STATUS_RUNNING if running?
|
6
8
|
return STATUS_WAITING if waiting?
|
7
|
-
|
9
|
+
|
10
|
+
last_fail_status.presence || STATUS_FAILED
|
8
11
|
end
|
9
12
|
|
10
13
|
def failed?
|
@@ -17,6 +20,7 @@ class ScheduledTask < ActiveRecord::Base
|
|
17
20
|
|
18
21
|
def waiting?
|
19
22
|
return true if ended?(last_run_successful_end, last_run_unsuccessful_end)
|
23
|
+
|
20
24
|
status_attributes.all? { |a| send(a).blank? }
|
21
25
|
end
|
22
26
|
|
@@ -27,11 +31,11 @@ class ScheduledTask < ActiveRecord::Base
|
|
27
31
|
end
|
28
32
|
|
29
33
|
def status_on_start
|
30
|
-
|
34
|
+
update!(last_run_start: Time.zone.now)
|
31
35
|
end
|
32
36
|
|
33
37
|
def status_on_end(exception, last_fail_status)
|
34
|
-
|
38
|
+
update!(
|
35
39
|
next_run: calculate_next_run,
|
36
40
|
(exception ? :last_run_unsuccessful_start : :last_run_successful_start) => last_run_start,
|
37
41
|
(exception ? :last_run_unsuccessful_end : :last_run_successful_end) => Time.zone.now,
|
@@ -42,7 +46,7 @@ class ScheduledTask < ActiveRecord::Base
|
|
42
46
|
end
|
43
47
|
|
44
48
|
def status_attributes
|
45
|
-
%w
|
49
|
+
%w[start successful_start successful_end unsuccessful_start unsuccessful_end].map do |a|
|
46
50
|
"last_run_#{a}"
|
47
51
|
end
|
48
52
|
end
|
data/config/routes.rb
CHANGED
data/exe/tasks_scheduler
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'rubygems'
|
4
5
|
require 'daemons'
|
5
6
|
require 'fileutils'
|
6
7
|
|
7
8
|
def find_rails_root(dir = Dir.pwd)
|
8
|
-
|
9
|
+
raise 'Rails root not found' if ['', '/', '.'].include?(dir)
|
9
10
|
return dir if File.exist?(File.expand_path('config/environment.rb', dir))
|
11
|
+
|
10
12
|
rails_root(File.dirname(dir))
|
11
13
|
end
|
12
14
|
|
@@ -1,11 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'rubygems'
|
4
5
|
require 'daemons'
|
5
6
|
|
6
7
|
def find_rails_root(dir = Dir.pwd)
|
7
|
-
|
8
|
+
raise 'Rails root not found' if ['', '/', '.'].include?(dir)
|
8
9
|
return dir if File.exist?(File.expand_path('config/environment.rb', dir))
|
10
|
+
|
9
11
|
rails_root(File.dirname(dir))
|
10
12
|
end
|
11
13
|
|
data/lib/tasks_scheduler.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'tasks_scheduler/checker/log'
|
2
4
|
|
3
5
|
module TasksScheduler
|
@@ -5,8 +7,8 @@ module TasksScheduler
|
|
5
7
|
include Singleton
|
6
8
|
|
7
9
|
CHECK_INTERVAL = 15
|
8
|
-
LOG_ON_FILE_ENV_KEY = 'TASKS_SCHEDULER_LOG_ON_FILE'
|
9
|
-
LOGS_KEYS = %w
|
10
|
+
LOG_ON_FILE_ENV_KEY = 'TASKS_SCHEDULER_LOG_ON_FILE'
|
11
|
+
LOGS_KEYS = %w[rails stdout stderr].freeze
|
10
12
|
|
11
13
|
def run
|
12
14
|
check_log
|
@@ -40,6 +42,7 @@ CODE
|
|
40
42
|
|
41
43
|
def check_log
|
42
44
|
return unless log_on_file?
|
45
|
+
|
43
46
|
::Rails.logger = ::Logger.new(rails_log.path)
|
44
47
|
$stdout.reopen(stdout_log.path, 'w')
|
45
48
|
$stderr.reopen(stderr_log.path, 'w')
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module TasksScheduler
|
2
4
|
module CronParserPatch
|
3
5
|
class TasksSchedulerTimeSource
|
4
6
|
class << self
|
5
|
-
def local(year, month, day, hour, min, second)
|
7
|
+
def local(year, month, day, hour, min, second) # rubocop:disable Metrics/ParameterLists
|
6
8
|
Time.utc(year, month, day, hour, min, second)
|
7
9
|
end
|
8
10
|
|
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module TasksScheduler
|
2
4
|
class CronSchedulingValidator < ActiveModel::EachValidator
|
3
5
|
def validate_each(record, attribute, value)
|
4
6
|
return if value_valid?(value)
|
7
|
+
|
5
8
|
record.errors[attribute] << (options[:message] ||
|
6
9
|
I18n.translate(:cron_scheduling_validator_error_message))
|
7
10
|
end
|
@@ -1,12 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'open3'
|
2
4
|
|
3
5
|
module TasksScheduler
|
4
6
|
class Daemon
|
5
|
-
ACTIONS = %w
|
7
|
+
ACTIONS = %w[status start stop restart].freeze
|
6
8
|
|
7
9
|
class << self
|
8
10
|
def execute(action)
|
9
11
|
raise "Action not allowed: #{action} (Allowed: #{ACTIONS})" unless ACTIONS.include?(action)
|
12
|
+
|
10
13
|
command = ['bundle', 'exec', 'tasks_scheduler', action]
|
11
14
|
Dir.chdir(Rails.root) do
|
12
15
|
Open3.popen3(env_args, *command) do |_stdin, stdout, stderr, wait_thr|
|
data/test/dummy/Rakefile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
4
|
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
5
|
|
4
|
-
require File.expand_path('
|
6
|
+
require File.expand_path('config/application', __dir__)
|
5
7
|
|
6
8
|
Rails.application.load_tasks
|
data/test/dummy/bin/bundle
CHANGED
data/test/dummy/bin/rails
CHANGED
data/test/dummy/bin/rake
CHANGED
data/test/dummy/bin/setup
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'pathname'
|
3
5
|
|
4
6
|
# path to your application root.
|
5
|
-
APP_ROOT = Pathname.new File.expand_path('
|
7
|
+
APP_ROOT = Pathname.new File.expand_path('..', __dir__)
|
6
8
|
|
7
9
|
Dir.chdir APP_ROOT do
|
8
10
|
# This script is a starting point to setup your application.
|
data/test/dummy/config.ru
CHANGED
data/test/dummy/config/boot.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Set up gems listed in the Gemfile.
|
2
|
-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('
|
4
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
|
3
5
|
|
4
6
|
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
5
|
-
$LOAD_PATH.unshift File.expand_path('
|
7
|
+
$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
|
data/test/dummy/config/routes.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class ScheduledTaskTest < ActiveSupport::TestCase
|
@@ -6,9 +8,9 @@ class ScheduledTaskTest < ActiveSupport::TestCase
|
|
6
8
|
'*/5 * * * *' => Time.utc(2016, 12, 22, 12, 5, 0, 0),
|
7
9
|
'* * 1 * *' => Time.utc(2017, 1, 1, 0, 0, 0, 0),
|
8
10
|
'* * * * *' => Time.utc(2016, 12, 22, 12, 1, 0, 0)
|
9
|
-
}
|
11
|
+
}.freeze
|
10
12
|
|
11
|
-
SCHEDULING_INVALID_VALUES = [' ', nil, '1', 'abc123', 456]
|
13
|
+
SCHEDULING_INVALID_VALUES = [' ', nil, '1', 'abc123', 456].freeze
|
12
14
|
|
13
15
|
setup do
|
14
16
|
@scheduled_task = scheduled_tasks(:test_scheduling)
|
@@ -57,7 +59,7 @@ class ScheduledTaskTest < ActiveSupport::TestCase
|
|
57
59
|
end
|
58
60
|
|
59
61
|
test 'status 1' do
|
60
|
-
@scheduled_task.
|
62
|
+
@scheduled_task.update!(
|
61
63
|
scheduling: '*/5 * * * *',
|
62
64
|
next_run: 'Wed, 28 Feb 2018 15:35:00 UTC +00:00',
|
63
65
|
created_at: 'Tue, 06 Dec 2016 20:30:01 UTC +00:00',
|
@@ -88,7 +90,7 @@ class ScheduledTaskTest < ActiveSupport::TestCase
|
|
88
90
|
assert_equal ['abc'], @scheduled_task.send('invoke_args')
|
89
91
|
|
90
92
|
@scheduled_task.args = 'abc|def|ghi'
|
91
|
-
assert_equal %w
|
93
|
+
assert_equal %w[abc def ghi], @scheduled_task.send('invoke_args')
|
92
94
|
|
93
95
|
@scheduled_task.args = 'abc||ghi'
|
94
96
|
assert_equal ['abc', '', 'ghi'], @scheduled_task.send('invoke_args')
|
data/test/test_helper.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Configure Rails Environment
|
2
4
|
ENV['RAILS_ENV'] = 'test'
|
3
5
|
|
4
|
-
require File.expand_path('
|
6
|
+
require File.expand_path('../test/dummy/config/environment.rb', __dir__)
|
5
7
|
ActiveRecord::Migrator.migrations_paths = [
|
6
|
-
File.expand_path('
|
8
|
+
File.expand_path('../test/dummy/db/migrate', __dir__)
|
7
9
|
]
|
8
10
|
require 'rails/test_help'
|
9
11
|
|
@@ -12,11 +14,11 @@ require 'rails/test_help'
|
|
12
14
|
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
13
15
|
|
14
16
|
# Load support files
|
15
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
17
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
|
16
18
|
|
17
19
|
# Load fixtures from the engine
|
18
20
|
if ActiveSupport::TestCase.respond_to?(:fixture_path=)
|
19
|
-
ActiveSupport::TestCase.fixture_path = File.expand_path('
|
21
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path('fixtures', __dir__)
|
20
22
|
ActiveSupport::TestCase.fixtures :all
|
21
23
|
end
|
22
24
|
|
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.
|
4
|
+
version: 0.4.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:
|
11
|
+
date: 2020-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_scaffold
|
@@ -212,41 +212,41 @@ signing_key:
|
|
212
212
|
specification_version: 4
|
213
213
|
summary: Scheduler for Rake tasks.
|
214
214
|
test_files:
|
215
|
-
- test/
|
215
|
+
- test/dummy/Rakefile
|
216
|
+
- test/dummy/README.rdoc
|
217
|
+
- test/dummy/config.ru
|
218
|
+
- test/dummy/config/boot.rb
|
219
|
+
- test/dummy/config/database.yml
|
220
|
+
- test/dummy/config/secrets.yml
|
221
|
+
- test/dummy/config/locales/en.yml
|
222
|
+
- test/dummy/config/application.rb
|
223
|
+
- test/dummy/config/environments/development.rb
|
224
|
+
- test/dummy/config/environments/test.rb
|
225
|
+
- test/dummy/config/environments/production.rb
|
226
|
+
- test/dummy/config/environment.rb
|
216
227
|
- test/dummy/config/routes.rb
|
217
228
|
- test/dummy/config/initializers/assets.rb
|
218
229
|
- test/dummy/config/initializers/cookies_serializer.rb
|
230
|
+
- test/dummy/config/initializers/inflections.rb
|
219
231
|
- test/dummy/config/initializers/session_store.rb
|
220
|
-
- test/dummy/config/initializers/backtrace_silencers.rb
|
221
232
|
- test/dummy/config/initializers/wrap_parameters.rb
|
222
233
|
- test/dummy/config/initializers/filter_parameter_logging.rb
|
223
|
-
- test/dummy/config/initializers/
|
234
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
224
235
|
- test/dummy/config/initializers/mime_types.rb
|
225
|
-
- test/dummy/
|
226
|
-
- test/dummy/config/secrets.yml
|
227
|
-
- test/dummy/config/locales/en.yml
|
228
|
-
- test/dummy/config/environment.rb
|
229
|
-
- test/dummy/config/boot.rb
|
230
|
-
- test/dummy/config/application.rb
|
231
|
-
- test/dummy/config/environments/production.rb
|
232
|
-
- test/dummy/config/environments/test.rb
|
233
|
-
- test/dummy/config/environments/development.rb
|
234
|
-
- test/dummy/Rakefile
|
235
|
-
- test/dummy/public/favicon.ico
|
236
|
-
- test/dummy/public/404.html
|
237
|
-
- test/dummy/public/500.html
|
238
|
-
- test/dummy/public/422.html
|
239
|
-
- test/dummy/config.ru
|
240
|
-
- test/dummy/app/assets/stylesheets/application.css
|
241
|
-
- test/dummy/app/assets/javascripts/application.js
|
242
|
-
- test/dummy/app/helpers/application_helper.rb
|
236
|
+
- test/dummy/db/schema.rb
|
243
237
|
- test/dummy/app/views/layouts/application.html.erb
|
244
238
|
- test/dummy/app/controllers/application_controller.rb
|
245
|
-
- test/dummy/
|
239
|
+
- test/dummy/app/helpers/application_helper.rb
|
240
|
+
- test/dummy/app/assets/stylesheets/application.css
|
241
|
+
- test/dummy/app/assets/javascripts/application.js
|
242
|
+
- test/dummy/public/422.html
|
243
|
+
- test/dummy/public/404.html
|
244
|
+
- test/dummy/public/favicon.ico
|
245
|
+
- test/dummy/public/500.html
|
246
246
|
- test/dummy/bin/bundle
|
247
|
+
- test/dummy/bin/setup
|
247
248
|
- test/dummy/bin/rails
|
248
249
|
- test/dummy/bin/rake
|
249
|
-
- test/dummy/db/schema.rb
|
250
|
-
- test/dummy/README.rdoc
|
251
250
|
- test/test_helper.rb
|
252
251
|
- test/fixtures/scheduled_tasks.yml
|
252
|
+
- test/models/scheduled_task_test.rb
|