This PR is for issue #50 , handling duplicate code for the .check_async() and .import_async() methods across different models.
Summary of Changes -
Creation of a module (inside lib directory) that hosts a run_task() method. This method takes in a model and a task, and contains the code that is shared among all the models in invoking a rake task via ECS task to check each service.
A private method, generate_command() was created to hold the logic of what the command should be, depending on which model the check is for.
The generate_command() method takes in a model and task, and uses a case statement to assign the correct command depending on the service/model.
Inside each model the check_async/import_async() method is replaced with a call to the Syncable module's run_task() method with the correct parameters.
module Syncable
def run_task(model, task)
# code
command = generate_command(model, task)
# code
overrides: {
container_overrides: [
{
name: config.ecs_async_task_container,
command: command
},
]
},
# code
end
private
def generate_command(model, task)
case model
when :internet_archive
['bin/rails', "books:check_internet_archive[#{task.id}]"]
when :hathitrust
['bin/rails', "books:check_hathitrust[#{task.id}]"]
when :google
['bin/rails', "books:check_google[#{@inventory_key},#{task.id}]"]
when :record_source
['bin/rails', "books:import[#{task.id}]"]
else
"no such model"
end
end
end
Each model includes the module to access the shared method.
e.g.
class Hathitrust
include Syncable
#code
def check_async(task)
run_task(:hathitrust, task)
end
#code
end
In order to load the Syncable module throughout the app, config/application.rbneeded to be updated with:
config.autoload_paths += %W(#{config.root}/lib}
I tested this locally just by running the different bin/rails commands (ie. bin/rails books:import) to make sure nothing broke
This PR is for issue #50 , handling duplicate code for the
.check_async()
and.import_async()
methods across different models.Summary of Changes -
module
(insidelib
directory) that hosts arun_task()
method. This method takes in amodel and a task
, and contains the code that is shared among all the models ininvoking a rake task via ECS task
to check each service.generate_command()
was created to hold the logic of what thecommand
should be, depending on which model the check is for.generate_command()
method takes in amodel
andtask
, and uses acase statement
to assign the correct command depending on the service/model.check_async/import_async()
method is replaced with a call to theSyncable module's run_task() method
with the correct parameters.e.g.
In order to load the Syncable module throughout the app,
config/application.rb
needed to be updated with:I tested this locally just by running the different bin/rails commands (ie. bin/rails books:import) to make sure nothing broke