maintenance_tasks 1.1.0 → 1.1.1

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: 3e274988d4a5facd653134ab4d4f2c51a71957ad8b2e6e1e16958f3726d50bb1
4
- data.tar.gz: beae97f203e12ed5017b9a76e1ced6b8d9f3e9e8ca8bc65a85a63d781d150bcf
3
+ metadata.gz: '017924f32ef1d9cb9e8ef6b739e1dc7ab60695dce1ee03c9f9f14fcaa35dfdde'
4
+ data.tar.gz: 17d3d2e220dd8b3cc7270797398abe33e5c90e38a3d19b28a571cb61c94a567c
5
5
  SHA512:
6
- metadata.gz: 67ed786c6c0281422ef4a10af1167c129cbab7422624656c3cae3eb3fe8f35bc5df00f874f2aee2a1eacf54fe957faccd5a4df12240e3f461b81817cdd5347a7
7
- data.tar.gz: 3cf190c896f046accf647b74e6acb58680b9e7eb89d25ea58e1a58e2db48e5437c5a410f2536c440c494efc599ea635a0380fc6a554ae157b53b402efbda4211
6
+ metadata.gz: '0942f2e8f1d23e1dc180a13deef7af7c198dcb348fdd62ed0c9107d4eded0a7908c0477c6e15c954658f4a99a41c5858fec4b02477d8deed4f72f44c4ae7cb5e'
7
+ data.tar.gz: 61c1d448e4c1eaf7a8076dc253d72de1d515b70ed4623b76a290b24dd4e6f0c76aff6fccde27619eceffc497ca750910aa9590363f2c3cbd2085a75a8838a18f
@@ -3,7 +3,7 @@
3
3
  module MaintenanceTasks
4
4
  # Base class for all controllers used by this engine.
5
5
  #
6
- # @api private
6
+ # Can be extended to add different authentication and authorization code.
7
7
  class ApplicationController < ActionController::Base
8
8
  include Pagy::Backend
9
9
 
@@ -22,5 +22,4 @@ module MaintenanceTasks
22
22
 
23
23
  protect_from_forgery with: :exception
24
24
  end
25
- private_constant :ApplicationController
26
25
  end
@@ -30,5 +30,4 @@ module MaintenanceTasks
30
30
  @run = Run.find(params.fetch(:id))
31
31
  end
32
32
  end
33
- private_constant :RunsController
34
33
  end
@@ -42,5 +42,4 @@ module MaintenanceTasks
42
42
  @refresh = 3
43
43
  end
44
44
  end
45
- private_constant :TasksController
46
45
  end
@@ -29,5 +29,4 @@ module MaintenanceTasks
29
29
  end
30
30
  end
31
31
  end
32
- private_constant :ApplicationHelper
33
32
  end
@@ -6,7 +6,7 @@ module MaintenanceTasks
6
6
  # Helpers for formatting data in the maintenance_tasks views.
7
7
  #
8
8
  # @api private
9
- module TaskHelper
9
+ module TasksHelper
10
10
  STATUS_COLOURS = {
11
11
  'new' => ['is-primary'],
12
12
  'enqueued' => ['is-primary is-light'],
@@ -114,5 +114,4 @@ module MaintenanceTasks
114
114
  )
115
115
  end
116
116
  end
117
- private_constant :TaskHelper
118
117
  end
@@ -97,8 +97,27 @@ module MaintenanceTasks
97
97
  @ticker.persist
98
98
  end
99
99
 
100
+ # We are reopening a private part of Job Iteration's API here, so we should
101
+ # ensure the method is still defined upstream. This way, in the case where
102
+ # the method changes upstream, we catch it at load time instead of at
103
+ # runtime while calling `super`.
104
+ unless private_method_defined?(:reenqueue_iteration_job)
105
+ error_message = <<~HEREDOC
106
+ JobIteration::Iteration#reenqueue_iteration_job is expected to be
107
+ defined. Upgrading the maintenance_tasks gem should solve this problem.
108
+ HEREDOC
109
+ raise error_message
110
+ end
111
+ def reenqueue_iteration_job(should_ignore: true)
112
+ super() unless should_ignore
113
+ @reenqueue_iteration_job = true
114
+ end
115
+
100
116
  def after_perform
101
117
  @run.save!
118
+ if defined?(@reenqueue_iteration_job) && @reenqueue_iteration_job
119
+ reenqueue_iteration_job(should_ignore: false)
120
+ end
102
121
  end
103
122
 
104
123
  def on_error(error)
@@ -2,9 +2,9 @@
2
2
  module MaintenanceTasks
3
3
  # Base class for all records used by this engine.
4
4
  #
5
- # @api private
5
+ # Can be extended to setup different database where all tables related to
6
+ # maintenance tasks will live.
6
7
  class ApplicationRecord < ActiveRecord::Base
7
8
  self.abstract_class = true
8
9
  end
9
- private_constant :ApplicationRecord
10
10
  end
@@ -30,5 +30,4 @@ module MaintenanceTasks
30
30
  csv_content.count("\n") - 1
31
31
  end
32
32
  end
33
- private_constant :CsvCollection
34
33
  end
@@ -49,7 +49,7 @@ module MaintenanceTasks
49
49
  def title
50
50
  if !total?
51
51
  "Processed #{@run.tick_count} #{'item'.pluralize(@run.tick_count)}."
52
- elsif @run.tick_count > @run.tick_total
52
+ elsif over_total?
53
53
  "Processed #{@run.tick_count} #{'item'.pluralize(@run.tick_count)} " \
54
54
  "(expected #{@run.tick_total})."
55
55
  else
@@ -67,8 +67,11 @@ module MaintenanceTasks
67
67
  end
68
68
 
69
69
  def estimatable?
70
- total? && @run.tick_total > @run.tick_count
70
+ total? && !over_total?
71
+ end
72
+
73
+ def over_total?
74
+ @run.tick_count > @run.tick_total
71
75
  end
72
76
  end
73
- private_constant :Progress
74
77
  end
@@ -195,5 +195,4 @@ module MaintenanceTasks
195
195
  nil
196
196
  end
197
197
  end
198
- private_constant :Run
199
198
  end
@@ -138,5 +138,4 @@ module MaintenanceTasks
138
138
  Run.where(task_name: name).with_attached_csv_file.order(created_at: :desc)
139
139
  end
140
140
  end
141
- private_constant :TaskData
142
141
  end
@@ -54,5 +54,4 @@ module MaintenanceTasks
54
54
  Time.now - @last_persisted >= @throttle_duration
55
55
  end
56
56
  end
57
- private_constant :Ticker
58
57
  end
@@ -16,9 +16,12 @@ module MaintenanceTasks
16
16
  #
17
17
  # @raise [NotFoundError] if a Task with the given name does not exist.
18
18
  def named(name)
19
- name.constantize
20
- rescue NameError
21
- raise NotFoundError.new("Task #{name} not found.", name)
19
+ task = name.safe_constantize
20
+ raise NotFoundError.new("Task #{name} not found.", name) unless task
21
+ unless task.is_a?(Class) && task < Task
22
+ raise NotFoundError.new("#{name} is not a Task.", name)
23
+ end
24
+ task
22
25
  end
23
26
 
24
27
  # Returns a list of concrete classes that inherit from the Task
@@ -85,5 +85,4 @@ module MaintenanceTasks
85
85
  )
86
86
  end
87
87
  end
88
- private_constant :RunStatusValidator
89
88
  end
@@ -1,5 +1,6 @@
1
1
  <h5 class="title is-5">
2
2
  <%= time_tag run.created_at, title: run.created_at %>
3
+ <%= status_tag run.status if with_status %>
3
4
  </h5>
4
5
 
5
6
  <%= progress run %>
@@ -1,8 +1,3 @@
1
1
  <div class="box">
2
- <h5 class="title is-5">
3
- <%= time_tag run.created_at, title: run.created_at %>
4
- <%= status_tag run.status %>
5
- </h5>
6
-
7
- <%= render 'maintenance_tasks/runs/info', run: run %>
2
+ <%= render 'maintenance_tasks/runs/info', run: run, with_status: true %>
8
3
  </div>
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ class RemoveIndexOnTaskName < ActiveRecord::Migration[6.1]
3
+ def up
4
+ change_table(:maintenance_tasks_runs) do |t|
5
+ t.remove_index(:task_name)
6
+ end
7
+ end
8
+
9
+ def down
10
+ change_table(:maintenance_tasks_runs) do |t|
11
+ t.index(:task_name)
12
+ end
13
+ end
14
+ end
@@ -18,5 +18,4 @@ module MaintenanceTasks
18
18
  rake('db:migrate')
19
19
  end
20
20
  end
21
- private_constant :InstallGenerator
22
21
  end
@@ -77,5 +77,4 @@ module MaintenanceTasks
77
77
  Rails.application.config.generators.options[:rails][:test_framework]
78
78
  end
79
79
  end
80
- private_constant :TaskGenerator
81
80
  end
@@ -9,6 +9,10 @@ require 'maintenance_tasks/engine'
9
9
  require 'pagy'
10
10
  require 'pagy/extras/bulma'
11
11
 
12
+ # Force the TaskJob class to load so we can verify upstream compatibility with
13
+ # the JobIteration gem
14
+ require_relative '../app/jobs/maintenance_tasks/task_job'
15
+
12
16
  # The engine's namespace module. It provides isolation between the host
13
17
  # application's code and the engine-specific code. Top-level engine constants
14
18
  # and variables are defined under this module.
@@ -51,5 +51,4 @@ module MaintenanceTasks
51
51
  end
52
52
  end
53
53
  end
54
- private_constant :CLI
55
54
  end
@@ -7,6 +7,10 @@ module MaintenanceTasks
7
7
  class Engine < ::Rails::Engine
8
8
  isolate_namespace MaintenanceTasks
9
9
 
10
+ initializer 'eager_load_for_classic_autoloader' do
11
+ eager_load! unless Rails.autoloaders.zeitwerk_enabled?
12
+ end
13
+
10
14
  config.to_prepare do
11
15
  unless Rails.autoloaders.zeitwerk_enabled?
12
16
  tasks_module = MaintenanceTasks.tasks_module.underscore
@@ -17,7 +21,6 @@ module MaintenanceTasks
17
21
  end
18
22
 
19
23
  config.after_initialize do
20
- eager_load! unless Rails.autoloaders.zeitwerk_enabled?
21
24
  JobIteration.max_job_runtime ||= 5.minutes
22
25
  end
23
26
 
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: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify Engineering
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-11 00:00:00.000000000 Z
11
+ date: 2021-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -107,7 +107,7 @@ files:
107
107
  - app/controllers/maintenance_tasks/runs_controller.rb
108
108
  - app/controllers/maintenance_tasks/tasks_controller.rb
109
109
  - app/helpers/maintenance_tasks/application_helper.rb
110
- - app/helpers/maintenance_tasks/task_helper.rb
110
+ - app/helpers/maintenance_tasks/tasks_helper.rb
111
111
  - app/jobs/maintenance_tasks/task_job.rb
112
112
  - app/models/maintenance_tasks/application_record.rb
113
113
  - app/models/maintenance_tasks/csv_collection.rb
@@ -136,6 +136,7 @@ files:
136
136
  - app/views/maintenance_tasks/tasks/show.html.erb
137
137
  - config/routes.rb
138
138
  - db/migrate/20201211151756_create_maintenance_tasks_runs.rb
139
+ - db/migrate/20210225152418_remove_index_on_task_name.rb
139
140
  - exe/maintenance_tasks
140
141
  - lib/generators/maintenance_tasks/install_generator.rb
141
142
  - lib/generators/maintenance_tasks/task_generator.rb
@@ -150,10 +151,10 @@ files:
150
151
  homepage: https://github.com/Shopify/maintenance_tasks
151
152
  licenses: []
152
153
  metadata:
153
- source_code_uri: https://github.com/Shopify/maintenance_tasks/tree/v1.1.0
154
+ source_code_uri: https://github.com/Shopify/maintenance_tasks/tree/v1.1.1
154
155
  allowed_push_host: https://rubygems.org
155
156
  post_install_message: |-
156
- Thank you for installing Maintenance Tasks 1.1.0. To complete, please run:
157
+ Thank you for installing Maintenance Tasks 1.1.1. To complete, please run:
157
158
 
158
159
  rails generate maintenance_tasks:install
159
160
  rdoc_options: []