maintenance_tasks 2.3.0 → 2.3.2

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: a14c442d683123d8aabb30db8c73c15a31ddd24852356aa64b0255b1cb2312e0
4
- data.tar.gz: d5df5cbfa0cf9feab143ae2ea15cb5a0013978b552a068d9a588fed4e04178bd
3
+ metadata.gz: cfca7a21544ab46b7d3c24464b29a6ac988dafa08ac8c2f22955d037932e1710
4
+ data.tar.gz: bdd38b4905fcf1248ca3c88ee8e29e74fb34ca10a226b6bdbd91507d61040250
5
5
  SHA512:
6
- metadata.gz: 528669b01c611fe0e502683665182bddb2a98f2a74911c5d957f3868fca2ff57323a07eb2093acdfedc39e44057f8346702f70fc67cf027f59a32b985a6f7cea
7
- data.tar.gz: bb00d7ef688b49ad9ae295650eea0b57718ea95aea6b341780011d882ae2b0f9ac830241cd9663d3bd7c9b9e08b3ee9bf6daa91a4ef2e4c53b69a15350c2da06
6
+ metadata.gz: 97f000fad025014bba55992c5d49e1c15557b34599a3a00d7815edf2c9da99aa2a660470ae96c58e89242b515f8e9c588ff9358ae65c5692649cc5f5805cfc10
7
+ data.tar.gz: aef9399c97ab570a58d5768426d1d2a3e4907b20eaa36dd304f36438a2139c84116358d9e71e63a8098371a3c653f1d1adab94486e6a5ce92508e637cdf62495
data/README.md CHANGED
@@ -840,8 +840,8 @@ or email of the user who performed the maintenance task.
840
840
 
841
841
  ```ruby
842
842
  # config/initializers/maintenance_tasks.rb
843
- MaintenanceTasks.metadata = -> do
844
- { user_email: current_user.email }
843
+ MaintenanceTasks.metadata = ->(context) do
844
+ { user_email: context.current_user.email }
845
845
  end
846
846
  ```
847
847
 
@@ -14,7 +14,7 @@ module MaintenanceTasks
14
14
  name: params.fetch(:task_id),
15
15
  csv_file: params[:csv_file],
16
16
  arguments: params.fetch(:task_arguments, {}).permit!.to_h,
17
- metadata: MaintenanceTasks.metadata&.call,
17
+ metadata: instance_exec(&MaintenanceTasks.metadata || -> {}),
18
18
  &block
19
19
  )
20
20
  redirect_to(task_path(task))
@@ -41,15 +41,27 @@ module MaintenanceTasks
41
41
  task
42
42
  end
43
43
 
44
- # Returns a list of concrete classes that inherit from the Task
45
- # superclass.
44
+ # Loads and returns a list of concrete classes that inherit
45
+ # from the Task superclass.
46
46
  #
47
47
  # @return [Array<Class>] the list of classes.
48
- def available_tasks
48
+ def load_all
49
49
  load_constants
50
50
  descendants
51
51
  end
52
52
 
53
+ # Loads and returns a list of concrete classes that inherit
54
+ # from the Task superclass.
55
+ #
56
+ # @return [Array<Class>] the list of classes.
57
+ def available_tasks
58
+ warn(<<~MSG.squish, category: :deprecated)
59
+ MaintenanceTasks::Task.available_tasks is deprecated and will be
60
+ removed from maintenance-tasks 3.0.0. Use .load_all instead.
61
+ MSG
62
+ load_all
63
+ end
64
+
53
65
  # Make this Task a task that handles CSV.
54
66
  #
55
67
  # @param in_batches [Integer] optionally, supply a batch size if the CSV
@@ -25,7 +25,7 @@ module MaintenanceTasks
25
25
  def available_tasks
26
26
  tasks = []
27
27
 
28
- task_names = Task.available_tasks.map(&:name)
28
+ task_names = Task.load_all.map(&:name)
29
29
 
30
30
  active_runs = Run.with_attached_csv.active.where(task_name: task_names)
31
31
  active_runs.each do |run|
@@ -16,15 +16,6 @@ module MaintenanceTasks
16
16
 
17
17
  desc "perform [TASK NAME]", "Runs the given Maintenance Task"
18
18
 
19
- long_desc <<-LONGDESC
20
- `maintenance_tasks perform` will run the Maintenance Task specified by the
21
- [TASK NAME] argument.
22
-
23
- Available Tasks:
24
-
25
- #{MaintenanceTasks::Task.available_tasks.join("\n\n")}
26
- LONGDESC
27
-
28
19
  # Specify the CSV file to process for CSV Tasks
29
20
  desc = "Supply a CSV file to be processed by a CSV Task, "\
30
21
  "--csv path/to/csv/file.csv"
@@ -50,6 +41,21 @@ module MaintenanceTasks
50
41
  say_status(:error, error.message, :red)
51
42
  end
52
43
 
44
+ # `long_desc` only allows us to use a static string as "long description".
45
+ # By redefining the `#long_description` method on the "perform" Command
46
+ # object instead, we make it dynamic, thus delaying the task loading
47
+ # process until it's actually required.
48
+ commands["perform"].define_singleton_method(:long_description) do
49
+ <<~LONGDESC
50
+ `maintenance_tasks perform` will run the Maintenance Task specified by
51
+ the [TASK NAME] argument.
52
+
53
+ Available Tasks:
54
+
55
+ #{Task.load_all.map(&:name).sort.join("\n\n")}
56
+ LONGDESC
57
+ end
58
+
53
59
  private
54
60
 
55
61
  def csv_file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maintenance_tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify Engineering
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-23 00:00:00.000000000 Z
11
+ date: 2023-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -56,14 +56,14 @@ dependencies:
56
56
  name: job-iteration
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.3.6
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.3.6
69
69
  - !ruby/object:Gem::Dependency
@@ -156,7 +156,7 @@ homepage: https://github.com/Shopify/maintenance_tasks
156
156
  licenses:
157
157
  - MIT
158
158
  metadata:
159
- source_code_uri: https://github.com/Shopify/maintenance_tasks/tree/v2.3.0
159
+ source_code_uri: https://github.com/Shopify/maintenance_tasks/tree/v2.3.2
160
160
  allowed_push_host: https://rubygems.org
161
161
  post_install_message:
162
162
  rdoc_options: []
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  - !ruby/object:Gem::Version
174
174
  version: '0'
175
175
  requirements: []
176
- rubygems_version: 3.4.18
176
+ rubygems_version: 3.4.19
177
177
  signing_key:
178
178
  specification_version: 4
179
179
  summary: A Rails engine for queuing and managing maintenance tasks