-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
791aaa0
commit b393eda
Showing
6 changed files
with
63 additions
and
49 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,34 +1,40 @@ | ||
class CompanyRegisterStatusJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(days_interval = 14, spam_time_delay=0.3) | ||
registrants = Registrant.where(ident_type: 'org') | ||
.where( | ||
'(company_register_status IS NULL) OR | ||
(company_register_status = ? AND (checked_company_at IS NULL OR checked_company_at <= ?)) OR | ||
(company_register_status = ? AND (checked_company_at IS NULL OR checked_company_at <= ?))', | ||
Contact::REGISTERED, days_interval.days.ago, | ||
Contact::LIQUIDATED, 1.day.ago | ||
) | ||
|
||
registrants.find_in_batches(batch_size: 100) do |contacts| | ||
|
||
def perform(days_interval = 14, spam_time_delay = 0.2, batch_size = 100) | ||
sampling_registrant_contact(days_interval).find_in_batches(batch_size: batch_size) do |contacts| | ||
contacts.each do |contact| | ||
|
||
# avoid spamming company register | ||
sleep spam_time_delay | ||
|
||
company_status = contact.return_company_status | ||
contact.company_register_status = company_status | ||
contact.checked_company_at = Time.zone.now | ||
contact.save! | ||
contact.update!(company_register_status: company_status, checked_company_at: Time.zone.now) | ||
|
||
next unless [Contact::BANKRUPT, Contact::DELETED].include? company_status | ||
|
||
next unless company_status == Contact::BANKRUPT || company_status == Contact::DELETED | ||
|
||
contact.domains.each do |domain| | ||
domain.schedule_force_delete(type: :fast_track, notify_by_email: true, reason: 'invalid_company', email: contact.email) | ||
end | ||
schedule_force_delete(contact) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def sampling_registrant_contact(days_interval) | ||
Registrant.where(ident_type: 'org') | ||
.where('(company_register_status IS NULL) OR | ||
(company_register_status = ? AND (checked_company_at IS NULL OR checked_company_at <= ?)) OR | ||
(company_register_status = ? AND (checked_company_at IS NULL OR checked_company_at <= ?))', | ||
Contact::REGISTERED, days_interval.days.ago, Contact::LIQUIDATED, 1.day.ago) | ||
end | ||
|
||
def schedule_force_delete(contact) | ||
contact.domains.each do |domain| | ||
domain.schedule_force_delete( | ||
type: :fast_track, | ||
notify_by_email: true, | ||
reason: 'invalid_company', | ||
email: contact.email | ||
) | ||
end | ||
end | ||
end |
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
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