Skip to content

Commit

Permalink
Merge pull request #193 from Ches-ctrl/2024-06-13-dev
Browse files Browse the repository at this point in the history
2024 06 13 dev
  • Loading branch information
Ches-ctrl authored Jun 29, 2024
2 parents 152b169 + 64c016a commit 6425988
Show file tree
Hide file tree
Showing 113 changed files with 25,806 additions and 2,478 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rubyonrails.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
run: bundle exec rspec
- name: Upload VCR log
if: failure()
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: vcr-log
path: log/vcr.log
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
!/tmp/storage/.keep

/public/assets
/public/data/**

# Ignore master key for decrypting credentials and more.
/config/master.key
Expand Down
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--require spec_helper
--require rails_helper
2 changes: 1 addition & 1 deletion app/assets/builds/tailwind.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/jobs/importer/api/devit_jobs_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class DevitJobsJob < ApplicationJob
sidekiq_options retry: false

def perform
Importer::Api::DevitJobs.new.import_jobs
Importer::Api::DevitJobs.new.call
end
end
end
Expand Down
12 changes: 0 additions & 12 deletions app/jobs/importer/url/create_company_from_url_job.rb

This file was deleted.

12 changes: 0 additions & 12 deletions app/jobs/importer/url/create_job_from_url_job.rb

This file was deleted.

10 changes: 10 additions & 0 deletions app/jobs/url/create_company_from_url_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Url
class CreateCompanyFromUrlJob < ApplicationJob
queue_as :default
retry_on StandardError, attempts: 0

def perform(url)
Importer::Url::CreateCompanyFromUrl.new(url).create_company
end
end
end
10 changes: 10 additions & 0 deletions app/jobs/url/create_devit_job_from_url_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Url
class CreateDevitJobFromUrlJob < ApplicationJob
queue_as :default
retry_on StandardError, attempts: 0

def perform(job_data)
DevitJobFetcher.call(job_data)
end
end
end
10 changes: 10 additions & 0 deletions app/jobs/url/create_job_from_url_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Url
class CreateJobFromUrlJob < ApplicationJob
queue_as :default
retry_on StandardError, attempts: 0

def self.perform(url)
Url::CreateJobFromUrl.new(url).create_company_then_job
end
end
end
15 changes: 14 additions & 1 deletion app/models/applicant_tracking_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ApplicantTrackingSystem < ApplicationRecord

# == Class Methods ========================================================
def self.determine_ats(url)
name = ATS_SYSTEM_PARSER.find { |regex, ats_name| break ats_name if url.match?(regex) }
name = fetch_ats_name_from_url(url)
return ApplicantTrackingSystem.find_by(name:)
end

Expand Down Expand Up @@ -76,4 +76,17 @@ def convert_from_iso8601(iso8601_string)
def convert_from_milliseconds(millisecond_string)
Time.at(millisecond_string.to_i / 1000) if millisecond_string
end

def self.fetch_ats_name_from_url(url)
url_path, url_parameters = url.split('?')
fetch_name(url_path) || fetch_name(url_parameters)
end

def self.fetch_name(string)
return unless string&.present?

ATS_SYSTEM_PARSER.find { |regex, ats_name| break ats_name if string.match?(regex) }
end

private_class_method :fetch_ats_name_from_url, :fetch_name
end
27 changes: 13 additions & 14 deletions app/models/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def url_present?(url_type)

# TODO: Have identified these as the primary drivers of slow test speed due to API calls. Need to decide on next steps.
# TODO: This is a very hacky temporary solution to speed up tests. Need to fix this
# TODO: Remove these as depenedencies - we will find another way to do this

def set_website_url
return if url_website.present?
Expand All @@ -49,18 +50,16 @@ def set_website_url
end
end

private

def fetch_industry
return unless industry == 'n/a'

if Rails.env.production?
industry, subcategory = Categorizer::CompanyIndustryService.lookup_industry(name, @name_keywords)
self.industry = industry
self.sub_industry = subcategory
else
self.industry = "Finance"
self.sub_industry = "Banking"
end
end
# def fetch_industry
# return unless industry == 'n/a'

# if Rails.env.production?
# industry, subcategory = Categorizer::CompanyIndustryService.lookup_industry(name, @name_keywords)
# self.industry = industry
# self.sub_industry = subcategory
# else
# self.industry = "Finance"
# self.sub_industry = "Banking"
# end
# end
end
4 changes: 2 additions & 2 deletions app/models/concerns/ats/ashbyhq/company_details.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module Ats
module Ashbyhq
module CompanyDetails
private

def company_details(ats_identifier)
url_ats_api = "#{url_api}#{ats_identifier}?includeCompensation=true"
{
Expand All @@ -26,6 +24,8 @@ def supplementary_data(ats_identifier)
}
end

private

def fetch_description(data)
[
data.dig('theme', 'jobBoardTopDescriptionHtml'),
Expand Down
27 changes: 9 additions & 18 deletions app/models/concerns/ats/ashbyhq/job_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,18 @@ def fetch_id(job_data)
job_data['id']
end

private

def fetch_job_data(job)
job_id = job.ats_job_id
all_jobs_data = get_json_data(job.api_url)
data = all_jobs_data["jobs"]&.find { |job| job["id"] == job_id }

return data if data
def job_url_api(url_api, ats_identifier, _job_id)
"#{url_api}#{ats_identifier}?includeCompensation=true"
end

p "Job with ID #{job_id} is expired."
job.live = false
return nil
def fetch_job_data(job_id, api_url, _ats_identifier)
all_jobs_data = get_json_data(api_url)
all_jobs_data["jobs"]&.find { |job| job["id"] == job_id }
end

def job_details(job, data)
def job_details(_job, data)
title, location = fetch_title_and_location(data)
job.assign_attributes(
{
title:,
description: Flipper.enabled?(:job_description) ? data['descriptionHtml'] : 'Not added yet',
non_geocoded_location_string: location,
Expand All @@ -41,11 +36,7 @@ def job_details(job, data)
# deadline: data['applicationDeadline'],
salary: data.dig('compensation', 'compensationTierSummary'), # more info available
remote: data['isRemote']
)
end

def job_url_api(url_api, ats_identifier, _job_id)
"#{url_api}#{ats_identifier}?includeCompensation=true"
}
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/ats/bamboohr/company_details.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module Ats
module Bamboohr
module CompanyDetails
private

def company_details(ats_identifier)
url_ats_api, url_ats_main = replace_ats_identifier(ats_identifier)
data = fetch_company_api_data(url_ats_main)
Expand All @@ -16,6 +14,8 @@ def company_details(ats_identifier)
}
end

private

def fetch_company_api_data(url_ats_main)
endpoint = "#{url_ats_main}company-info/"
data = get_json_data(endpoint)
Expand Down
24 changes: 12 additions & 12 deletions app/models/concerns/ats/bamboohr/job_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ def fetch_id(job_data)
job_data['id']
end

private
def job_url_api(_base_url, ats_identifier, job_id)
company = Company.find_by(ats_identifier:)
"#{company.url_ats_main}#{job_id}/detail"
end

def fetch_job_data(_job_id, api_url, _ats_identifier)
get_json_data(api_url)&.dig('result')
end

def job_details(job, data)
def job_details(_job, data)
data = data['jobOpening']
job.assign_attributes(
{
title: data['jobOpeningName'],
description: Flipper.enabled?(:job_description) ? data['description'] : 'Not added yet',
salary: data['compensation'],
Expand All @@ -35,17 +42,10 @@ def job_details(job, data)
non_geocoded_location_string: build_location_string(data),
posting_url: data['jobOpeningShareUrl'],
live: data['jobOpeningStatus'] == 'Open'
)
}
end

def job_url_api(_base_url, ats_identifier, job_id)
company = Company.find_by(ats_identifier:)
"#{company.url_ats_main}#{job_id}/detail"
end

def fetch_job_data(job)
get_json_data(job.api_url)&.dig('result')
end
private

def job_remote?(data)
data['locationType'] == '1'
Expand Down
37 changes: 3 additions & 34 deletions app/models/concerns/ats/company_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,10 @@ module CompanyCreator
# TODO: Refactor this to simplify down
# TODO: Refactor into a service object according to the Single Responsibility Principle

def find_or_create_company_by_data(data)
ats_identifier = fetch_company_id(data)
find_or_create_company(ats_identifier, data)
rescue StandardError => e
Rails.logger.error "Error creating company: #{e.message}"
nil
end

def find_or_create_company(ats_identifier, data = nil)
return unless ats_identifier

company = Company.find_or_initialize_by(ats_identifier:) do |new_company|
company_data = company_details(ats_identifier)

new_company.applicant_tracking_system = self
new_company.assign_attributes(company_data)
end

if data
supplementary_data = company_details_from_data(data)
company.assign_attributes(supplementary_data)
end

if company.new_record? && company.save
CompanyDescriptionFetcher.call(company)
company.set_website_url
Rails.logger.info "Company created - #{company.name}"
end

return company
end

def company_details(ats_identifier, data = nil)
refer_to_module(defined?(super) ? super : nil, __method__)
end

private

def company_details_from_data(data)
data
end
Expand All @@ -50,7 +16,10 @@ def fetch_company_id(data)
refer_to_module(defined?(super) ? super : nil, __method__)
end

private

def fetch_company_name(ats_identifier)
p "Fetching company name from clearbit"
url = "https://autocomplete.clearbit.com/v1/companies/suggest?query=#{ats_identifier}"
data = get_json_data(url)
return data.dig(0, 'name') unless data.blank?
Expand Down
5 changes: 3 additions & 2 deletions app/models/concerns/ats/devitjobs/company_details.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module Ats
module Devitjobs
module CompanyDetails
private

def fetch_company_id(data)
p "Fetching company ID"
data['company'].gsub(' ', '-').gsub(/[^A-Za-z\-]/, '')
end

def company_details(ats_identifier)
p "Fetching company details"
{
url_ats_api: "https://devitjobs.uk/api/companyPages/#{ats_identifier}",
url_ats_main: "https://devitjobs.uk/companies/#{ats_identifier}",
Expand All @@ -16,6 +16,7 @@ def company_details(ats_identifier)
end

def company_details_from_data(data)
p "Fetching company details from data"
{
name: data['company'],
url_website: data['companyWebsiteLink'],
Expand Down
1 change: 1 addition & 0 deletions app/models/concerns/ats/devitjobs/fetch_company_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module FetchCompanyJobs
include CheckUrlIsValid

def fetch_company_jobs(ats_identifier)
p "Fetching company jobs"
data = get_json_data(url_all_jobs)
data.select { |job_data| job_data['jobUrl'].include?(ats_identifier) }
end
Expand Down
Loading

0 comments on commit 6425988

Please sign in to comment.