effective_developer 0.6.7 → 0.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ca9f6ec3b73f4a7f2e31b382f9030769e13b82b43835bd7a74f4efa41a07c24
4
- data.tar.gz: f21c929b19f4d9c4e645f90cc85cda28f4d0e3c1413689b294b7326bde095359
3
+ metadata.gz: f51117606ee26c0266dfac742502712dc318a8b09148d722f928b3efd8dc404e
4
+ data.tar.gz: 4fd2b3a0fd954b1c0f0d9716e6ee33c911365a3f71aa0141c7e60b5294c8a7bc
5
5
  SHA512:
6
- metadata.gz: 8ce3d22243ef79b452009c2e20e993bea861489b4cca95f4eba7d27f0fa11a305e272298d19cbd8fab2b829d1004b690202c6769dfab239f671e82ddcc49a524
7
- data.tar.gz: 54fd14f769c558937de317edb4e00dc3114775a1f58b948fe5723bea590cecd1a0c9d7958aefac45b06a82558582b527f3bf0dd0224f6dc6d61fd3eabe6cfb61
6
+ metadata.gz: f5c5588277544f359c0e8481f9f273dc90f34f3831c8e2b3a8e3394a93657a0c863b1d699db00aa707fd7c716e29c47e9904319ac4405b1f82bac8ca89a4c759
7
+ data.tar.gz: 6f55724df58ff196884dcd26ff7e2e274b800eae283bacf1b9ef5759f338edc8dfca73d0bc7b1fbf5ba90e6c3e1f9bbfabd434bc88bedb8dbcbe5a6f040a1975
@@ -2,9 +2,6 @@ module EffectiveDeveloper
2
2
  class Engine < ::Rails::Engine
3
3
  engine_name 'effective_developer'
4
4
 
5
- config.autoload_paths += Dir["#{config.root}/models/jobs/"]
6
- config.eager_load_paths += Dir["#{config.root}/models/jobs/"]
7
-
8
5
  # Set up our default configuration options.
9
6
  initializer 'effective_developer.defaults', before: :load_config_initializers do |app|
10
7
  # Set up our defaults, as per our initializer template
@@ -1,3 +1,3 @@
1
1
  module EffectiveDeveloper
2
- VERSION = '0.6.7'.freeze
2
+ VERSION = '0.6.8'.freeze
3
3
  end
@@ -0,0 +1,11 @@
1
+ # bundle exec rake hb:ssh
2
+ # bundle exec rake hb:staging
3
+ namespace :hb do
4
+ task :ssh do
5
+ system("ssh -t deploy@#{ENV.fetch('HATCHBOX_IP')} \"cd ~/arta/current ; bash --login\"")
6
+ end
7
+
8
+ task :staging do
9
+ system("ssh -t deploy@#{ENV.fetch('HATCHBOX_IP')} \"cd ~/arta-staging/current ; bash --login\"")
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ # bundle exec rake sidekiq:start
2
+ # bundle exec rake sidekiq:clear
3
+
4
+ namespace :sidekiq do
5
+ desc 'Starts the sidekiq background job server'
6
+ task :start do
7
+ system('bundle exec sidekiq -C config/sidekiq.yml')
8
+ end
9
+
10
+ desc 'Clears all in progress sidekiq jobs'
11
+ task clear: :environment do
12
+ unless Rails.env.development?
13
+ puts "Cannot run in non-development mode"; exit
14
+ end
15
+
16
+ require 'sidekiq/api'
17
+ Sidekiq::Queue.all.each { |q| q.clear }
18
+
19
+ puts "All sidekiq queues cleared"
20
+ end
21
+
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_developer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-21 00:00:00.000000000 Z
11
+ date: 2021-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -48,16 +48,12 @@ files:
48
48
  - MIT-LICENSE
49
49
  - README.md
50
50
  - Rakefile
51
- - app/jobs/effective/asset_replacer_job.rb
52
- - app/jobs/effective/snippet_replacer_job.rb
53
51
  - app/models/effective/annotator.rb
54
- - app/models/effective/asset_replacer.rb
55
52
  - app/models/effective/code_writer.rb
56
53
  - app/models/effective/csv_importer.rb
57
54
  - app/models/effective/form_upgrader.rb
58
55
  - app/models/effective/live_generator.rb
59
56
  - app/models/effective/profiler.rb
60
- - app/models/effective/snippet_replacer.rb
61
57
  - config/effective_developer.rb
62
58
  - lib/effective_developer.rb
63
59
  - lib/effective_developer/engine.rb
@@ -103,11 +99,11 @@ files:
103
99
  - lib/scaffolds/views/_resource.html.haml
104
100
  - lib/tasks/annotate.rake
105
101
  - lib/tasks/effective_csv_importer.rake
102
+ - lib/tasks/hatchbox.rake
106
103
  - lib/tasks/pg_pull.rake
107
104
  - lib/tasks/rename_class.rake
108
- - lib/tasks/replace_effective_assets.rake
109
- - lib/tasks/replace_effective_snippets.rake
110
105
  - lib/tasks/reset_pk_sequence.rake
106
+ - lib/tasks/sidekiq_clear.rake
111
107
  - lib/tasks/upgrade_forms.rake
112
108
  - lib/tasks/validate.rake
113
109
  homepage: https://github.com/code-and-effect/effective_developer
@@ -1,17 +0,0 @@
1
- module Effective
2
- class AssetReplacerJob < ::ApplicationJob
3
-
4
- queue_as :default
5
-
6
- if defined?(Sidekiq)
7
- # The retry setting works. But none of these waits seem to. Still getting exponential backoff.
8
- sidekiq_options retry: 2, retry_in: 10, wait: 10
9
- sidekiq_retry_in { |count, exception| 10 }
10
- end
11
-
12
- def perform(attachment, box)
13
- Effective::AssetReplacer.new.replace_attachment!(attachment, box)
14
- end
15
-
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- module Effective
2
- class SnippetReplacerJob < ::ApplicationJob
3
-
4
- queue_as :default
5
-
6
- if defined?(Sidekiq)
7
- # The retry setting works. But none of these waits seem to. Still getting exponential backoff.
8
- sidekiq_options retry: 2, retry_in: 10, wait: 10
9
- sidekiq_retry_in { |count, exception| 10 }
10
- end
11
-
12
- def perform(region)
13
- Effective::SnippetReplacer.new.replace_region!(region)
14
- end
15
-
16
- end
17
- end
@@ -1,156 +0,0 @@
1
- # Looks at the Effective::Asset and Effective::Attachments and converts to ActiveStorage
2
- #
3
- # 1. Put in the has_attached_files to each model to be upgraded
4
- # 2. Remove the acts_as_asset_box
5
-
6
- require 'timeout'
7
-
8
- module Effective
9
- class AssetReplacer
10
- include ActiveStorage::Blob::Analyzable
11
-
12
- BATCH_SIZE = 500
13
- TIMEOUT = 120
14
-
15
- def replace!(skip_existing: false)
16
- verify!
17
-
18
- attachments = attachments_to_process().to_a
19
-
20
- while(true)
21
- wait_for_active_job!
22
-
23
- puts "\nEnqueuing #{attachments.length} attachments with ids #{attachments.first.id} to #{attachments.last.id}"
24
-
25
- attachments.each do |attachment|
26
- asset = attachment.asset
27
- attachable = attachment.attachable
28
- next if asset.blank? || attachable.blank?
29
-
30
- box = attachment.box.singularize
31
- boxes = attachment.box
32
-
33
- one = attachable.respond_to?(box) && attachable.send(box).kind_of?(ActiveStorage::Attached::One)
34
- many = attachable.respond_to?(boxes) && attachable.send(boxes).kind_of?(ActiveStorage::Attached::Many)
35
- box = (one ? box : boxes)
36
-
37
- if skip_existing
38
- existing = Array(attachable.send(box))
39
-
40
- if existing.any? { |obj| obj.respond_to?(:filename) && obj.filename.to_s == asset.file_name }
41
- puts("Skipping existing #{attachable.class.name} #{attachable.id} #{box} #{asset.file_name}.")
42
- next
43
- end
44
- end
45
-
46
- Effective::AssetReplacerJob.perform_later(attachment, box)
47
- end
48
-
49
- attachments = attachments_to_process().where.not(id: attachments.map(&:id))
50
- break if attachments.to_a.blank?
51
-
52
- GC.start
53
- end
54
-
55
- puts "\nAll Done. Have a great day."
56
- true
57
- end
58
-
59
- # This is called on the background by the AssetReplacerJob
60
- def replace_attachment!(attachment, box)
61
- raise('expected an Effective::Attachment') unless attachment.kind_of?(Effective::Attachment)
62
- puts("Processing attachment ##{attachment.id}")
63
-
64
- asset = attachment.asset
65
- attachable = attachment.attachable
66
-
67
- attachable.replacing_asset = true if attachable.respond_to?(:replacing_asset=)
68
-
69
- Timeout.timeout(TIMEOUT) do
70
- attachable.send(box).attach(
71
- io: URI.open(asset.url),
72
- filename: asset.file_name,
73
- content_type: asset.content_type.presence,
74
- identify: (asset.content_type.blank?)
75
- )
76
-
77
- attachment.update_column(:replaced, true)
78
- end
79
-
80
- true
81
- end
82
-
83
- def verify!
84
- raise('expected effective assets') unless defined?(Effective::Asset)
85
- raise('expected active storage') unless defined?(ActiveStorage)
86
-
87
- unless Effective::Attachment.new.respond_to?(:replaced?)
88
- raise('please add a replaced boolean to Effective::Attachment. add_column :attachments, :replaced, :boolean')
89
- end
90
-
91
- (Effective::Attachment.all.pluck(:attachable_type, :box).uniq).each do |name, boxes|
92
- next if name.blank? || boxes.blank?
93
-
94
- box = boxes.singularize
95
-
96
- klass = name.safe_constantize
97
- raise("invalid class #{klass}") unless klass.present?
98
-
99
- instance = klass.new
100
-
101
- if instance.respond_to?(:effective_assets)
102
- raise("please remove acts_as_asset_box() from #{klass.name}")
103
- end
104
-
105
- unless instance.respond_to?(box) || instance.respond_to?(boxes)
106
- raise("expected #{klass.name} to has_one_attached :#{box} or has_many_attached :#{boxes}")
107
- end
108
-
109
- one = instance.respond_to?(box) && instance.send(box).kind_of?(ActiveStorage::Attached::One)
110
- many = instance.respond_to?(boxes) && instance.send(boxes).kind_of?(ActiveStorage::Attached::Many)
111
-
112
- unless one.present? || many.present?
113
- raise("expected #{klass.name} to has_one_attached :#{box} or has_many_attached :#{boxes}")
114
- end
115
- end
116
-
117
- puts 'All attachment classes verified.'
118
-
119
- true
120
- end
121
-
122
- def reset!
123
- Effective::Attachment.update_all(replaced: false)
124
- end
125
-
126
- private
127
-
128
- def wait_for_active_job!
129
- while(true)
130
- if(jobs = enqueued_jobs_count) > (BATCH_SIZE / 10)
131
- print '.'; sleep(3)
132
- else
133
- break
134
- end
135
- end
136
- end
137
-
138
- # The last BATCH_SIZE attachments
139
- def attachments_to_process
140
- Effective::Attachment.all
141
- .includes(:asset)
142
- .where(replaced: [nil, false])
143
- .reorder(id: :desc)
144
- .limit(BATCH_SIZE)
145
- end
146
-
147
- def enqueued_jobs_count
148
- if Rails.application.config.active_job.queue_adapter == :sidekiq
149
- Sidekiq::Stats.new.enqueued.to_i
150
- else
151
- ActiveJob::Base.queue_adapter.enqueued_jobs.count
152
- end
153
- end
154
-
155
- end
156
- end
@@ -1,67 +0,0 @@
1
- # Replaces the [snippet_x] in all effective regions with static content
2
-
3
- module Effective
4
- class SnippetReplacer
5
- include ActiveStorage::Blob::Analyzable
6
- include ActionView::Helpers::UrlHelper
7
- include ActionView::Helpers::AssetTagHelper
8
-
9
- def replace!
10
- raise('expected effective regions') unless defined?(Effective::Region)
11
- raise('expected effective assets') unless defined?(Effective::Asset)
12
- raise('expected active storage') unless defined?(ActiveStorage)
13
-
14
- Effective::Region.with_snippets.find_each do |region|
15
- Effective::SnippetReplacerJob.perform_later(region)
16
- end
17
-
18
- puts 'All Done. Background jobs are running. Have a great day.'
19
- true
20
- end
21
-
22
- def replace_region!(region)
23
- region.snippet_objects.each do |snippet|
24
- print('.')
25
-
26
- begin
27
- case snippet.class.name
28
- when 'Effective::Snippets::EffectiveAsset'
29
- replace_effective_asset(region, snippet)
30
- else
31
- raise("unsupported snippet: #{snippet.class.name}")
32
- end
33
- rescue => e
34
- puts "\nError: #{e}\n"
35
- remove_snippet(region, snippet)
36
- end
37
- end
38
-
39
- region.save!
40
- end
41
-
42
- def replace_effective_asset(region, snippet)
43
- asset = snippet.asset
44
- raise("Effective:Asset id=#{snippet.asset_id || 'none'} does not exist") unless asset.present?
45
-
46
- blob = ActiveStorage::Blob.create_and_upload!(io: URI.open(asset.url), filename: asset.file_name)
47
- url = Rails.application.routes.url_helpers.rails_blob_url(blob, only_path: true)
48
-
49
- content = if asset.image?
50
- image_tag(url, class: snippet.html_class, alt: snippet.link_title)
51
- else
52
- link_to(snippet.link_title, url, class: snippet.html_class, title: snippet.link_title)
53
- end
54
-
55
- region.content.sub!("[#{snippet.id}]", content.to_s)
56
- region.snippets.delete(snippet.id)
57
-
58
- true
59
- end
60
-
61
- def remove_snippet(region, snippet)
62
- region.content.sub!("[#{snippet.id}]", '')
63
- region.snippets.delete(snippet.id)
64
- end
65
-
66
- end
67
- end
@@ -1,5 +0,0 @@
1
- # bundle exec rake replace_effective_assets
2
- desc 'Replaces effective_assets with ActiveStorage'
3
- task :replace_effective_assets => :environment do
4
- Effective::AssetReplacer.new.replace!
5
- end
@@ -1,5 +0,0 @@
1
- # bundle exec rake replace_effective_snippets
2
- desc 'Replaces effective_assets snippets with ActiveStorage uploads'
3
- task :replace_effective_snippets => :environment do
4
- Effective::SnippetReplacer.new.replace!
5
- end