maintenance_tasks 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +316 -0
  3. data/Rakefile +29 -0
  4. data/app/controllers/maintenance_tasks/application_controller.rb +26 -0
  5. data/app/controllers/maintenance_tasks/runs_controller.rb +44 -0
  6. data/app/controllers/maintenance_tasks/tasks_controller.rb +42 -0
  7. data/app/helpers/maintenance_tasks/application_helper.rb +67 -0
  8. data/app/helpers/maintenance_tasks/task_helper.rb +110 -0
  9. data/app/jobs/maintenance_tasks/task_job.rb +98 -0
  10. data/app/models/maintenance_tasks/application_record.rb +10 -0
  11. data/app/models/maintenance_tasks/progress.rb +74 -0
  12. data/app/models/maintenance_tasks/run.rb +180 -0
  13. data/app/models/maintenance_tasks/runner.rb +52 -0
  14. data/app/models/maintenance_tasks/task_data.rb +137 -0
  15. data/app/models/maintenance_tasks/ticker.rb +58 -0
  16. data/app/tasks/maintenance_tasks/task.rb +83 -0
  17. data/app/validators/maintenance_tasks/run_status_validator.rb +86 -0
  18. data/app/views/layouts/maintenance_tasks/_navbar.html.erb +11 -0
  19. data/app/views/layouts/maintenance_tasks/application.html.erb +54 -0
  20. data/app/views/maintenance_tasks/runs/_info.html.erb +10 -0
  21. data/app/views/maintenance_tasks/runs/_run.html.erb +11 -0
  22. data/app/views/maintenance_tasks/runs/index.html.erb +15 -0
  23. data/app/views/maintenance_tasks/runs/info/_cancelled.html.erb +4 -0
  24. data/app/views/maintenance_tasks/runs/info/_cancelling.html.erb +1 -0
  25. data/app/views/maintenance_tasks/runs/info/_enqueued.html.erb +1 -0
  26. data/app/views/maintenance_tasks/runs/info/_errored.html.erb +25 -0
  27. data/app/views/maintenance_tasks/runs/info/_interrupted.html.erb +1 -0
  28. data/app/views/maintenance_tasks/runs/info/_paused.html.erb +8 -0
  29. data/app/views/maintenance_tasks/runs/info/_pausing.html.erb +1 -0
  30. data/app/views/maintenance_tasks/runs/info/_running.html.erb +7 -0
  31. data/app/views/maintenance_tasks/runs/info/_succeeded.html.erb +5 -0
  32. data/app/views/maintenance_tasks/tasks/_task.html.erb +8 -0
  33. data/app/views/maintenance_tasks/tasks/actions/_cancelled.html.erb +1 -0
  34. data/app/views/maintenance_tasks/tasks/actions/_cancelling.html.erb +4 -0
  35. data/app/views/maintenance_tasks/tasks/actions/_enqueued.html.erb +2 -0
  36. data/app/views/maintenance_tasks/tasks/actions/_errored.html.erb +1 -0
  37. data/app/views/maintenance_tasks/tasks/actions/_interrupted.html.erb +2 -0
  38. data/app/views/maintenance_tasks/tasks/actions/_new.html.erb +1 -0
  39. data/app/views/maintenance_tasks/tasks/actions/_paused.html.erb +2 -0
  40. data/app/views/maintenance_tasks/tasks/actions/_pausing.html.erb +2 -0
  41. data/app/views/maintenance_tasks/tasks/actions/_running.html.erb +2 -0
  42. data/app/views/maintenance_tasks/tasks/actions/_succeeded.html.erb +1 -0
  43. data/app/views/maintenance_tasks/tasks/index.html.erb +22 -0
  44. data/app/views/maintenance_tasks/tasks/show.html.erb +25 -0
  45. data/config/routes.rb +19 -0
  46. data/db/migrate/20201211151756_create_maintenance_tasks_runs.rb +22 -0
  47. data/exe/maintenance_tasks +13 -0
  48. data/lib/generators/maintenance_tasks/install_generator.rb +22 -0
  49. data/lib/generators/maintenance_tasks/task_generator.rb +74 -0
  50. data/lib/generators/maintenance_tasks/templates/task.rb.tt +21 -0
  51. data/lib/generators/maintenance_tasks/templates/task_spec.rb.tt +14 -0
  52. data/lib/generators/maintenance_tasks/templates/task_test.rb.tt +12 -0
  53. data/lib/maintenance_tasks.rb +58 -0
  54. data/lib/maintenance_tasks/cli.rb +40 -0
  55. data/lib/maintenance_tasks/engine.rb +28 -0
  56. data/lib/maintenance_tasks/integrations/bugsnag_handler.rb +4 -0
  57. data/lib/tasks/maintenance_tasks_tasks.rake +5 -0
  58. metadata +187 -0
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+
5
+ module MaintenanceTasks
6
+ # Defines the command line interface commands exposed by Maintenance Tasks in
7
+ # the executable file.
8
+ class CLI < Thor
9
+ class << self
10
+ # Return a failed exit status in case of an error.
11
+ def exit_on_failure?
12
+ true
13
+ end
14
+ end
15
+
16
+ desc 'perform [TASK NAME]', 'Runs the given Maintenance Task'
17
+
18
+ long_desc <<-LONGDESC
19
+ `maintenance_tasks perform` will run the Maintenance Task specified by the
20
+ [TASK NAME] argument.
21
+
22
+ Available Tasks:
23
+
24
+ #{MaintenanceTasks::Task.available_tasks.join("\n\n")}
25
+ LONGDESC
26
+
27
+ # Command to run a Task.
28
+ #
29
+ # It instantiates a Runner and sends a run message with the given Task name.
30
+ #
31
+ # @param name [String] the name of the Task to be run.
32
+ def perform(name)
33
+ task = Runner.new.run(name: name)
34
+ say_status(:success, "#{task.name} was enqueued.", :green)
35
+ rescue => error
36
+ say_status(:error, error.message, :red)
37
+ end
38
+ end
39
+ private_constant :CLI
40
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ require 'active_record/railtie'
3
+
4
+ module MaintenanceTasks
5
+ # The engine's main class, which defines its namespace. The engine is mounted
6
+ # by the host application.
7
+ class Engine < ::Rails::Engine
8
+ isolate_namespace MaintenanceTasks
9
+
10
+ config.to_prepare do
11
+ unless Rails.autoloaders.zeitwerk_enabled?
12
+ tasks_module = MaintenanceTasks.tasks_module.underscore
13
+ Dir["#{Rails.root}/app/tasks/#{tasks_module}/*.rb"].each do |file|
14
+ require_dependency(file)
15
+ end
16
+ end
17
+ end
18
+
19
+ config.after_initialize do
20
+ eager_load! unless Rails.autoloaders.zeitwerk_enabled?
21
+ JobIteration.max_job_runtime ||= 5.minutes
22
+ end
23
+
24
+ config.action_dispatch.rescue_responses.merge!(
25
+ 'MaintenanceTasks::Task::NotFoundError' => :not_found,
26
+ )
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ require 'bugsnag'
3
+
4
+ MaintenanceTasks.error_handler = ->(error) { Bugsnag.notify(error) }
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ # desc "Explaining what the task does"
3
+ # task :maintenance_tasks do
4
+ # # Task goes here
5
+ # end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maintenance_tasks
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Shopify Engineering
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-01-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activejob
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '6.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '6.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activerecord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '6.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '6.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: job-iteration
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pagy
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.9'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: railties
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '6.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '6.0'
97
+ description:
98
+ email: gems@shopify.com
99
+ executables:
100
+ - maintenance_tasks
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - README.md
105
+ - Rakefile
106
+ - app/controllers/maintenance_tasks/application_controller.rb
107
+ - app/controllers/maintenance_tasks/runs_controller.rb
108
+ - app/controllers/maintenance_tasks/tasks_controller.rb
109
+ - app/helpers/maintenance_tasks/application_helper.rb
110
+ - app/helpers/maintenance_tasks/task_helper.rb
111
+ - app/jobs/maintenance_tasks/task_job.rb
112
+ - app/models/maintenance_tasks/application_record.rb
113
+ - app/models/maintenance_tasks/progress.rb
114
+ - app/models/maintenance_tasks/run.rb
115
+ - app/models/maintenance_tasks/runner.rb
116
+ - app/models/maintenance_tasks/task_data.rb
117
+ - app/models/maintenance_tasks/ticker.rb
118
+ - app/tasks/maintenance_tasks/task.rb
119
+ - app/validators/maintenance_tasks/run_status_validator.rb
120
+ - app/views/layouts/maintenance_tasks/_navbar.html.erb
121
+ - app/views/layouts/maintenance_tasks/application.html.erb
122
+ - app/views/maintenance_tasks/runs/_info.html.erb
123
+ - app/views/maintenance_tasks/runs/_run.html.erb
124
+ - app/views/maintenance_tasks/runs/index.html.erb
125
+ - app/views/maintenance_tasks/runs/info/_cancelled.html.erb
126
+ - app/views/maintenance_tasks/runs/info/_cancelling.html.erb
127
+ - app/views/maintenance_tasks/runs/info/_enqueued.html.erb
128
+ - app/views/maintenance_tasks/runs/info/_errored.html.erb
129
+ - app/views/maintenance_tasks/runs/info/_interrupted.html.erb
130
+ - app/views/maintenance_tasks/runs/info/_paused.html.erb
131
+ - app/views/maintenance_tasks/runs/info/_pausing.html.erb
132
+ - app/views/maintenance_tasks/runs/info/_running.html.erb
133
+ - app/views/maintenance_tasks/runs/info/_succeeded.html.erb
134
+ - app/views/maintenance_tasks/tasks/_task.html.erb
135
+ - app/views/maintenance_tasks/tasks/actions/_cancelled.html.erb
136
+ - app/views/maintenance_tasks/tasks/actions/_cancelling.html.erb
137
+ - app/views/maintenance_tasks/tasks/actions/_enqueued.html.erb
138
+ - app/views/maintenance_tasks/tasks/actions/_errored.html.erb
139
+ - app/views/maintenance_tasks/tasks/actions/_interrupted.html.erb
140
+ - app/views/maintenance_tasks/tasks/actions/_new.html.erb
141
+ - app/views/maintenance_tasks/tasks/actions/_paused.html.erb
142
+ - app/views/maintenance_tasks/tasks/actions/_pausing.html.erb
143
+ - app/views/maintenance_tasks/tasks/actions/_running.html.erb
144
+ - app/views/maintenance_tasks/tasks/actions/_succeeded.html.erb
145
+ - app/views/maintenance_tasks/tasks/index.html.erb
146
+ - app/views/maintenance_tasks/tasks/show.html.erb
147
+ - config/routes.rb
148
+ - db/migrate/20201211151756_create_maintenance_tasks_runs.rb
149
+ - exe/maintenance_tasks
150
+ - lib/generators/maintenance_tasks/install_generator.rb
151
+ - lib/generators/maintenance_tasks/task_generator.rb
152
+ - lib/generators/maintenance_tasks/templates/task.rb.tt
153
+ - lib/generators/maintenance_tasks/templates/task_spec.rb.tt
154
+ - lib/generators/maintenance_tasks/templates/task_test.rb.tt
155
+ - lib/maintenance_tasks.rb
156
+ - lib/maintenance_tasks/cli.rb
157
+ - lib/maintenance_tasks/engine.rb
158
+ - lib/maintenance_tasks/integrations/bugsnag_handler.rb
159
+ - lib/tasks/maintenance_tasks_tasks.rake
160
+ homepage: https://github.com/Shopify/maintenance_tasks
161
+ licenses: []
162
+ metadata:
163
+ source_code_uri: https://github.com/Shopify/maintenance_tasks/tree/v1.0.0
164
+ allowed_push_host: https://rubygems.org
165
+ post_install_message: |-
166
+ Thank you for installing Maintenance Tasks 1.0.0. To complete, please run:
167
+
168
+ rails generate maintenance_tasks:install
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubygems_version: 3.0.3
184
+ signing_key:
185
+ specification_version: 4
186
+ summary: A Rails engine for queuing and managing maintenance tasks
187
+ test_files: []