Class: Spree::MaintenanceTasks::Upgrade::RakeStep

Inherits:
Spree::MaintenanceTask show all
Defined in:
app/maintenance_tasks/spree/maintenance_tasks/upgrade/rake_step.rb

Overview

Base for the one-pass upgrade steps that ask the operator for parameters (docs/plans/6.0-maintenance-tasks.md). The rake body stays the implementation; this class only maps its parameters onto the environment variables the body reads. A step without parameters runs through UpgradeStep and needs no class at all.

Constant Summary collapse

ENVIRONMENT_LOCK =
Mutex.new

Constants inherited from Spree::MaintenanceTask

Spree::MaintenanceTask::DEFAULT_BATCH_SIZE, Spree::MaintenanceTask::MAX_RUN_TIME, Spree::MaintenanceTask::RAKE_LOAD_LOCK

Instance Attribute Summary

Attributes inherited from Spree::MaintenanceTask

#run

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Spree::MaintenanceTask

#after_complete, api_type_for, #collection, collection_batch_size, #count, #dry_run?, find_by_api_type, find_registered, #invoke_rake_task, no_collection, #no_collection?, #rake_file_defining, registered_classes, supports_dry_run, #tallies, #tally

Methods included from ApiTyped

#api_type, api_type_for, #api_typed_family, class_name_for, find, registered_class

Class Method Details

.arguments_from_environment ⇒ Hash{String => String}

The declared parameters an operator exported before running the upgrade walk, so the walk passes them on rather than letting each attribute's default overwrite them.

Returns:

  • (Hash{String => String})


39
40
41
42
43
# File 'app/maintenance_tasks/spree/maintenance_tasks/upgrade/rake_step.rb', line 39

def self.arguments_from_environment
  environment_parameters.each_with_object({}) do |(attribute_name, variable), arguments|
    arguments[attribute_name.to_s] = ENV[variable] if ENV.key?(variable)
  end
end

.passes_to_environment(attribute_name, as:) ⇒ Object

Declares a parameter the rake body reads from the environment.

These bodies were written for a shell, so their answers arrive as environment variables. Mapping them to attributes records the answer on the run, and lets ARGS supply it when the step is run on its own.

Parameters:

  • attribute_name (Symbol)
  • as (String) —

    the environment variable the body reads



30
31
32
# File 'app/maintenance_tasks/spree/maintenance_tasks/upgrade/rake_step.rb', line 30

def self.passes_to_environment(attribute_name, as:)
  self.environment_parameters = environment_parameters.merge(attribute_name.to_sym => as).freeze
end

.runs_rake_task(name) ⇒ Object

Parameters:

  • name (String) —

    the rake task this step runs



18
19
20
# File 'app/maintenance_tasks/spree/maintenance_tasks/upgrade/rake_step.rb', line 18

def self.runs_rake_task(name)
  self.rake_task_name = name
end

Instance Method Details

#process ⇒ Object



45
46
47
# File 'app/maintenance_tasks/spree/maintenance_tasks/upgrade/rake_step.rb', line 45

def process
  with_environment { invoke_rake_task(self.class.rake_task_name) }
end