effective_developer 0.6.5 → 0.6.6
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3a6071b2027da0c4eb454ff1d2446f014c557a99cb495190c5594d2d9ecda81
|
4
|
+
data.tar.gz: 3bdec7afda572520e2ac59ba94ca47116ea4019a2b582cc71e6c4bd0e28e0467
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c013f0c196b01b41860abe74341736f2a5bffbc45781a5190c38e68cb642145c5de1784b3473183a83e1b72fc97991be459f169f7d72165f37961c406a17115
|
7
|
+
data.tar.gz: 27a7d4470f8c02d76826e220861d9f43fa6cbe715059363a3fa010721878541586f6d831281114226806075adcb00bc994bb96deb1a1fdca49e0fe3addfbc365
|
@@ -12,10 +12,12 @@ module Effective
|
|
12
12
|
BATCH_SIZE = 500
|
13
13
|
TIMEOUT = 120
|
14
14
|
|
15
|
-
def replace!(
|
15
|
+
def replace!(skip_existing: false)
|
16
16
|
verify!
|
17
17
|
|
18
|
-
attachments_to_process().
|
18
|
+
attachments = attachments_to_process().to_a
|
19
|
+
|
20
|
+
while(true)
|
19
21
|
wait_for_active_job!
|
20
22
|
|
21
23
|
puts "\nEnqueuing #{attachments.length} attachments with ids #{attachments.first.id} to #{attachments.last.id}"
|
@@ -32,16 +34,22 @@ module Effective
|
|
32
34
|
many = attachable.respond_to?(boxes) && attachable.send(boxes).kind_of?(ActiveStorage::Attached::Many)
|
33
35
|
box = (one ? box : boxes)
|
34
36
|
|
35
|
-
|
37
|
+
if skip_existing
|
36
38
|
existing = Array(attachable.send(box))
|
37
39
|
|
38
40
|
if existing.any? { |obj| obj.respond_to?(:filename) && obj.filename.to_s == asset.file_name }
|
39
|
-
puts("Skipping
|
41
|
+
puts("Skipping existing #{attachable.class.name} #{attachable.id} #{box} #{asset.file_name}.")
|
42
|
+
next
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
43
46
|
Effective::AssetReplacerJob.perform_later(attachment, box)
|
44
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
|
45
53
|
end
|
46
54
|
|
47
55
|
puts "\nAll Done. Have a great day."
|
@@ -56,7 +64,7 @@ module Effective
|
|
56
64
|
asset = attachment.asset
|
57
65
|
attachable = attachment.attachable
|
58
66
|
|
59
|
-
attachable.
|
67
|
+
attachable.replacing_asset = true if attachable.respond_to?(:replacing_asset=)
|
60
68
|
|
61
69
|
Timeout.timeout(TIMEOUT) do
|
62
70
|
attachable.send(box).attach(
|
@@ -120,15 +128,20 @@ module Effective
|
|
120
128
|
def wait_for_active_job!
|
121
129
|
while(true)
|
122
130
|
if(jobs = enqueued_jobs_count) > (BATCH_SIZE / 10)
|
123
|
-
print '.'; sleep(
|
131
|
+
print '.'; sleep(3)
|
124
132
|
else
|
125
133
|
break
|
126
134
|
end
|
127
135
|
end
|
128
136
|
end
|
129
137
|
|
138
|
+
# The last BATCH_SIZE attachments
|
130
139
|
def attachments_to_process
|
131
|
-
Effective::Attachment.all
|
140
|
+
Effective::Attachment.all
|
141
|
+
.includes(:asset)
|
142
|
+
.where(replaced: [nil, false])
|
143
|
+
.reorder(id: :desc)
|
144
|
+
.limit(BATCH_SIZE)
|
132
145
|
end
|
133
146
|
|
134
147
|
def enqueued_jobs_count
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# bundle exec rake
|
1
|
+
# bundle exec rake replace_effective_assets
|
2
2
|
desc 'Replaces effective_assets with ActiveStorage'
|
3
|
-
task :
|
3
|
+
task :replace_effective_assets => :environment do
|
4
4
|
Effective::AssetReplacer.new.replace!
|
5
5
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# bundle exec rake
|
1
|
+
# bundle exec rake replace_effective_snippets
|
2
2
|
desc 'Replaces effective_assets snippets with ActiveStorage uploads'
|
3
|
-
task :
|
3
|
+
task :replace_effective_snippets => :environment do
|
4
4
|
Effective::SnippetReplacer.new.replace!
|
5
5
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_developer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
@@ -104,8 +104,8 @@ files:
|
|
104
104
|
- lib/tasks/effective_csv_importer.rake
|
105
105
|
- lib/tasks/pg_pull.rake
|
106
106
|
- lib/tasks/rename_class.rake
|
107
|
-
- lib/tasks/
|
108
|
-
- lib/tasks/
|
107
|
+
- lib/tasks/replace_effective_assets.rake
|
108
|
+
- lib/tasks/replace_effective_snippets.rake
|
109
109
|
- lib/tasks/reset_pk_sequence.rake
|
110
110
|
- lib/tasks/upgrade_forms.rake
|
111
111
|
- lib/tasks/validate.rake
|