-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The principle behind this refactor is to use Composition instead of Inheritance. Now the Upload class is not a God object but a class with a single responsibility: Upload the XML given contents into the DWP SFTP server Inbox. The orchrestration of the query-->xml-->upload is now managed by each service class: - PublishedAndUpdated - ClosedEarly The names of these classes have been adapted to match Teaching Vacancies domain language. These classes are not anaemic classes anymore.
- Loading branch information
Showing
20 changed files
with
194 additions
and
140 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
app/services/vacancies/export/dwp_find_a_job/closed_early.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Vacancies::Export::DwpFindAJob | ||
class ClosedEarly | ||
include Vacancies::Export::DwpFindAJob::ClosedEarlyVacancies | ||
|
||
attr_reader :from_date | ||
|
||
def initialize(from_date) | ||
@from_date = from_date | ||
end | ||
|
||
def call | ||
vacancies = Query.new(from_date).vacancies | ||
xml = Xml.new(vacancies).xml | ||
|
||
Upload.new(xml: xml, filename: filename).call | ||
|
||
Rails.logger.info("[DWP Find a Job] Uploaded '#{filename}.xml': Containing #{vacancies.size} vacancies to close.") | ||
end | ||
|
||
private | ||
|
||
def filename | ||
@filename ||= "TeachingVacancies-expire-#{Time.zone.now.strftime('%Y%m%d-%H%M%S')}" | ||
end | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
...p_find_a_job/expired_and_deleted/query.rb → ...ind_a_job/closed_early_vacancies/query.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...dwp_find_a_job/expired_and_deleted/xml.rb → ..._find_a_job/closed_early_vacancies/xml.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
app/services/vacancies/export/dwp_find_a_job/expired_and_deleted/upload.rb
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
app/services/vacancies/export/dwp_find_a_job/new_and_edited/upload.rb
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
app/services/vacancies/export/dwp_find_a_job/published_and_updated.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Vacancies::Export::DwpFindAJob | ||
class PublishedAndUpdated | ||
include Vacancies::Export::DwpFindAJob::PublishedAndUpdatedVacancies | ||
|
||
attr_reader :from_date | ||
|
||
def initialize(from_date) | ||
@from_date = from_date | ||
end | ||
|
||
def call | ||
vacancies = Query.new(from_date).vacancies | ||
xml = Xml.new(vacancies).xml | ||
|
||
Upload.new(xml: xml, filename: filename).call | ||
|
||
Rails.logger.info("[DWP Find a Job] Uploaded '#{filename}.xml': Containing #{vacancies.size} vacancies to publish.") | ||
end | ||
|
||
private | ||
|
||
def filename | ||
@filename ||= "TeachingVacancies-upload-#{Time.zone.now.strftime('%Y%m%d-%H%M%S')}" | ||
end | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
...nd_a_job/new_and_edited/parsed_vacancy.rb → ...d_and_updated_vacancies/parsed_vacancy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rt/dwp_find_a_job/new_and_edited/query.rb → .../published_and_updated_vacancies/query.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...port/dwp_find_a_job/new_and_edited/xml.rb → ...ob/published_and_updated_vacancies/xml.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Vacancies::Export::DwpFindAJob | ||
class Upload | ||
attr_reader :xml, :filename | ||
|
||
def initialize(xml:, filename:) | ||
@xml = xml | ||
@filename = filename | ||
end | ||
|
||
def call | ||
file = Tempfile.new(filename) | ||
begin | ||
file.write(xml) | ||
file.flush # Ensure all data is written to disk before uploading | ||
upload_to_find_a_job_sftp(file.path) | ||
ensure | ||
file.close! | ||
end | ||
end | ||
|
||
private | ||
|
||
def upload_to_find_a_job_sftp(file_path) | ||
Net::SFTP.start(ENV.fetch("FIND_A_JOB_FTP_HOST", ""), | ||
ENV.fetch("FIND_A_JOB_FTP_USER", ""), | ||
password: ENV.fetch("FIND_A_JOB_FTP_PASSWORD", ""), | ||
port: ENV.fetch("FIND_A_JOB_FTP_PORT", "")) do |sftp| | ||
sftp.upload!(file_path, "Inbound/#{filename}.xml") | ||
end | ||
end | ||
end | ||
end |
47 changes: 0 additions & 47 deletions
47
app/services/vacancies/export/dwp_find_a_job/upload_base.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.