Skip to content

Commit 8bc7826

Browse files
authored
Merge branch 'main' into fix/file-worker-timeout
2 parents 702c4b0 + 4f40a87 commit 8bc7826

File tree

10 files changed

+92
-53
lines changed

10 files changed

+92
-53
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ gem "importmap-rails"
1414
gem "jbuilder"
1515
gem "kamal", require: false
1616
gem "mission_control-jobs"
17+
gem "ox"
1718
gem "pagy"
1819
gem "pg", "~> 1.6"
1920
gem "propshaft"

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ GEM
301301
nokogiri (1.18.9-x86_64-linux-musl)
302302
racc (~> 1.4)
303303
ostruct (0.6.3)
304+
ox (2.14.23)
305+
bigdecimal (>= 3.0)
304306
pagy (9.3.5)
305307
parallel (1.27.0)
306308
parser (3.3.9.0)
@@ -543,6 +545,7 @@ DEPENDENCIES
543545
kamal
544546
letter_opener
545547
mission_control-jobs
548+
ox
546549
pagy
547550
pg (~> 1.6)
548551
propshaft

app/services/language_content_processor.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ def provider_files
2525
# this is needed to avoid loading all files into memory at once
2626
def language_files
2727
{
28-
all_providers: FileToUpload.new(
29-
content: ->(language) { XmlGenerator::AllProviders.new(language).perform },
30-
name: "#{language.file_storage_prefix}Server_XML.xml",
31-
path: "#{language.file_storage_prefix}CMES-Pi/assets/XML",
32-
),
33-
all_providers_recent: FileToUpload.new(
34-
content: ->(language) { XmlGenerator::AllProviders.new(language, recent: true).perform },
35-
name: "#{language.file_storage_prefix}New_Uploads_Server_XML.xml",
36-
path: "#{language.file_storage_prefix}CMES-Pi/assets/XML",
37-
),
28+
# all_providers: FileToUpload.new(
29+
# content: ->(language) { XmlGenerator::AllProviders.new(language).perform },
30+
# name: "#{language.file_storage_prefix}Server_XML.xml",
31+
# path: "#{language.file_storage_prefix}CMES-Pi/assets/XML",
32+
# ),
33+
# all_providers_recent: FileToUpload.new(
34+
# content: ->(language) { XmlGenerator::AllProviders.new(language, recent: true).perform },
35+
# name: "#{language.file_storage_prefix}New_Uploads_Server_XML.xml",
36+
# path: "#{language.file_storage_prefix}CMES-Pi/assets/XML",
37+
# ),
3838
tags: FileToUpload.new(
3939
content: ->(language) { TextGenerator::Tags.new(language).perform },
4040
name: "#{language.file_storage_prefix}tags.txt",

app/services/xml_generator/all_providers.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ def initialize(language, **args)
88

99
def xml_content(xml)
1010
language.providers.includes(:topics)
11-
.map do |provider|
12-
provider_xml(xml, provider)
11+
.each do |provider|
12+
xml << provider_xml(provider)
1313
end
1414
end
1515
end

app/services/xml_generator/base.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
class XmlGenerator::Base
22
def perform
3-
builder.to_xml
3+
Ox.dump(builder)
44
end
55

66
private
77

88
def builder
9-
Nokogiri::XML::Builder.new do |xml|
10-
xml.cmes { xml_content(xml) }
9+
Ox::Document.new.tap do |doc|
10+
instruct = Ox::Instruct.new(:xml)
11+
instruct[:version] = "1.0"
12+
doc << instruct
13+
14+
xml = Ox::Element.new("cmes")
15+
xml_content(xml)
16+
doc << xml
1117
end
1218
end
1319
end

app/services/xml_generator/single_provider.rb

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,39 @@ def initialize(provider, **args)
99
attr_reader :provider, :args
1010

1111
def xml_content(xml)
12-
provider_xml(xml, provider)
12+
xml << provider_xml(provider)
1313
end
1414

15-
def provider_xml(xml, provider)
16-
xml.content_provider(name: provider.name) {
15+
def provider_xml(provider)
16+
Ox::Element.new("content_provider").tap do |xml|
17+
xml[:name] = provider.name
18+
1719
grouped_topics(provider).each do |(year, month), topics|
18-
xml.topic_year(year: year) {
19-
xml.topic_month(month: month) {
20+
xml << Ox::Element.new("topic_year").tap do |year_element|
21+
year_element[:year] = year.to_s
22+
year_element << Ox::Element.new("topic_month").tap do |month_element|
23+
month_element[:month] = month
2024
topics.each do |topic|
21-
xml.title(name: topic.title) {
22-
xml.topic_id topic.id
23-
xml.topic_files(files: "Files") {
25+
month_element << Ox::Element.new("title").tap do |title_element|
26+
title_element[:name] = topic.title
27+
title_element << Ox::Element.new("topic_id").tap { |id| id << topic.id.to_s }
28+
title_element << Ox::Element.new("topic_files").tap do |files|
29+
files[:files] = "Files"
2430
topic.documents.each_with_index do |document, index|
2531
next if document.content_type == "video/mp4"
26-
xml.send("file_name_#{index + 1}", document.filename, file_size: document.byte_size)
32+
files << Ox::Element.new("file_name_#{index + 1}").tap do |file_name|
33+
file_name << document.filename.to_s
34+
file_name[:file_size] = document.byte_size
35+
end
2736
end
28-
}
29-
xml.topic_tags topic.current_tags_list.join(", ")
30-
}
37+
end
38+
title_element << Ox::Element.new("topic_tags").tap { |tags| tags << topic.current_tags_list.join(", ") }
39+
end
3140
end
32-
}
33-
}
41+
end
42+
end
3443
end
35-
}
44+
end
3645
end
3746

3847
def grouped_topics(prov)

config/deploy.production.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,28 @@ registry:
1919
# Production environment variables
2020
env:
2121
secret:
22-
- RAILS_MASTER_KEY
23-
- DATABASE_URL
24-
- SECRET_KEY_BASE
2522
- AWS_ACCESS_KEY_ID
2623
- AWS_SECRET_ACCESS_KEY
27-
- AZURE_STORAGE_ACCOUNT_NAME
2824
- AZURE_STORAGE_ACCOUNT_KEY
25+
- AZURE_STORAGE_ACCOUNT_NAME
26+
- DATABASE_URL
27+
- RAILS_MASTER_KEY
28+
- SECRET_KEY_BASE
2929
- SCOUT_KEY
3030
clear:
31-
RAILS_ENV: production
32-
AWS_DEFAULT_REGION: us-east-1
3331
AWS_BUCKET_NAME: skillrx-production
34-
SCOUT_APP_NAME: "SkillRX Production"
32+
AWS_DEFAULT_REGION: us-east-1
3533
AWS_ENDPOINT_URL: "" # Empty for real AWS
3634
AZURE_STORAGE_SHARE_NAME: contentshare
37-
AZURE_MEDIA_FILES_SYNC_DISABLED: "true"
35+
DATA_IMPORT_SOURCE: azure
3836
LOCALSTACK_DEBUG: "0"
37+
RAILS_ENV: production
38+
RAILS_MAX_THREADS: 5
3939
S3_SKIP_SIGNATURE_VALIDATION: "0"
40+
SCOUT_APP_NAME: SkillRX Production
4041
SOLID_QUEUE_IN_PUMA: true
41-
DATA_IMPORT_SOURCE: azure
42+
WEB_CONCURRENCY: 2
43+
4244

4345
aliases:
4446
console: app exec --interactive --reuse "bin/rails console"

config/deploy.staging.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,27 @@ registry:
1919
# Staging environment variables
2020
env:
2121
secret:
22-
- RAILS_MASTER_KEY
23-
- DATABASE_URL
24-
- SECRET_KEY_BASE
2522
- AWS_ACCESS_KEY_ID
2623
- AWS_SECRET_ACCESS_KEY
27-
- AZURE_STORAGE_ACCOUNT_NAME
2824
- AZURE_STORAGE_ACCOUNT_KEY
25+
- AZURE_STORAGE_ACCOUNT_NAME
26+
- DATABASE_URL
27+
- RAILS_MASTER_KEY
28+
- SECRET_KEY_BASE
2929
- SCOUT_KEY
3030
clear:
31-
RAILS_ENV: production
32-
AWS_DEFAULT_REGION: us-east-1
3331
AWS_BUCKET_NAME: skillrx-staging
34-
SCOUT_APP_NAME: "SkillRX Staging"
35-
AZURE_STORAGE_SHARE_NAME: skillrx-staging-env
32+
AWS_DEFAULT_REGION: us-east-1
3633
AWS_ENDPOINT_URL: "" # Empty for real AWS
34+
AZURE_STORAGE_SHARE_NAME: skillrx-staging-env
35+
DATA_IMPORT_SOURCE: azure
3736
LOCALSTACK_DEBUG: "0"
38-
S3_SKIP_SIGNATURE_VALIDATION: "0"
37+
RAILS_ENV: production
3938
RAILS_MAX_THREADS: 5
40-
WEB_CONCURRENCY: 2
39+
S3_SKIP_SIGNATURE_VALIDATION: "0"
40+
SCOUT_APP_NAME: SkillRX Staging
4141
SOLID_QUEUE_IN_PUMA: true
42-
DATA_IMPORT_SOURCE: azure
42+
WEB_CONCURRENCY: 2
4343

4444
aliases:
4545
console: app exec --interactive --reuse "bin/rails console"

db/seeds.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,21 @@
107107
end
108108

109109
puts "Users created!"
110+
111+
if ENV["SEED_MODE_HEAVY_LOAD"]
112+
times = ENV["SEED_MODE_HEAVY_LOAD"].to_i
113+
times.times do
114+
provider = Provider.find_or_create_by!(name: Faker::Company.name, provider_type: "government")
115+
times.times do
116+
Topic.find_or_create_by!(
117+
title: Faker::Book.title,
118+
description: Faker::Lorem.paragraph,
119+
language_id: Language.first.id,
120+
provider_id: provider.id,
121+
uid: SecureRandom.uuid,
122+
published_at: Time.now - rand(1..365).days,
123+
state: [ :active, :archived ].sample,
124+
)
125+
end
126+
end
127+
end

spec/services/language_content_processor_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
end
1616

1717
it "processes content for every language" do
18-
files_number = language.providers.size + 9 # 2 xml files for all provides, 2 text files for tags, 5 csv files
18+
files_number = language.providers.size + 7 # 2 xml files for all provides, 2 text files for tags, 5 csv files
1919
subject.perform
2020

2121
expect(FileUploadJob).to have_received(:perform_later).exactly(files_number).times
2222

23-
expect(FileUploadJob).to have_received(:perform_later).with(language.id, "all_providers", "file")
24-
expect(FileUploadJob).to have_received(:perform_later).with(language.id, "all_providers_recent", "file")
23+
# expect(FileUploadJob).to have_received(:perform_later).with(language.id, "all_providers", "file")
24+
# expect(FileUploadJob).to have_received(:perform_later).with(language.id, "all_providers_recent", "file")
2525
expect(FileUploadJob).to have_received(:perform_later).with(language.id, "tags", "file")
2626
expect(FileUploadJob).to have_received(:perform_later).with(language.id, "tags_and_title", "file")
2727
expect(FileUploadJob).to have_received(:perform_later).with(language.id, "files", "file")

0 commit comments

Comments
 (0)