Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Task.available_tasks to .load_all and deprecate #878

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions app/models/maintenance_tasks/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,27 @@ def named(name)
task
end

# Returns a list of concrete classes that inherit from the Task
# superclass.
# Loads and returns a list of concrete classes that inherit
# from the Task superclass.
#
# @return [Array<Class>] the list of classes.
def available_tasks
def load_all
load_constants
descendants
end

# Loads and returns a list of concrete classes that inherit
# from the Task superclass.
#
# @return [Array<Class>] the list of classes.
def available_tasks
warn(<<~MSG.squish, category: :deprecated)
MaintenanceTasks::Task.available_tasks is deprecated and will be
removed from maintenance-tasks 3.0.0. Use .load_all instead.
MSG
load_all
end

# Make this Task a task that handles CSV.
#
# @param in_batches [Integer] optionally, supply a batch size if the CSV
Expand Down
2 changes: 1 addition & 1 deletion app/models/maintenance_tasks/task_data_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class << self
def available_tasks
tasks = []

task_names = Task.available_tasks.map(&:name)
task_names = Task.load_all.map(&:name)

active_runs = Run.with_attached_csv.active.where(task_name: task_names)
active_runs.each do |run|
Expand Down
2 changes: 1 addition & 1 deletion lib/maintenance_tasks/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def perform(name)

Available Tasks:

#{Task.available_tasks.map(&:name).sort.join("\n\n")}
#{Task.load_all.map(&:name).sort.join("\n\n")}
LONGDESC
end

Expand Down
2 changes: 1 addition & 1 deletion test/lib/maintenance_tasks/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class CLITest < ActiveSupport::TestCase

test "`help perform` loads all tasks and displays them" do
Task
.expects(:available_tasks)
.expects(:load_all)
.at_least_once
.returns([stub(name: "Task1"), stub(name: "Task2")])

Expand Down
15 changes: 13 additions & 2 deletions test/models/maintenance_tasks/task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module MaintenanceTasks
class TaskTest < ActiveSupport::TestCase
test ".available_tasks returns list of tasks that inherit from the Task superclass" do
test ".load_all returns list of tasks that inherit from the Task superclass" do
expected = [
"Maintenance::BatchImportPostsTask",
"Maintenance::CallbackTestTask",
Expand All @@ -23,7 +23,18 @@ class TaskTest < ActiveSupport::TestCase
"Maintenance::UpdatePostsThrottledTask",
]
assert_equal expected,
MaintenanceTasks::Task.available_tasks.map(&:name).sort
MaintenanceTasks::Task.load_all.map(&:name).sort
end

test ".available_tasks raises a deprecation warning before calling .load_all" do
expected_warning =
"MaintenanceTasks::Task.available_tasks is deprecated and will be " \
"removed from maintenance-tasks 3.0.0. Use .load_all instead.\n"

Warning.expects(:warn).with(expected_warning, category: :deprecated)
Task.expects(:load_all)

Task.available_tasks
end

test ".named returns the task based on its name" do
Expand Down