Skip to content

Commit

Permalink
Removed wait_time from WishlistJob
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergei Tsoganov authored and Sergei Tsoganov committed Oct 3, 2023
1 parent 30c46c6 commit 73d86ef
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 21 deletions.
12 changes: 3 additions & 9 deletions app/jobs/wishlist_job.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
class WishlistJob < ApplicationJob
LONG_WAIT_TIME = 2.hours
SHORT_WAIT_TIME = 1.minute

def perform(domain_name, auction_remote_id)
wishlist_items = WishlistItem.where(domain_name: domain_name)
auction = Auction.where('ends_at > ?', Time.zone.now)
auction = Auction.where.not(starts_at: nil).where('ends_at > ?', Time.zone.now)
.find_by(remote_id: auction_remote_id)
return unless auction

wishlist_items.each do |item|
next if item.processed?

WishlistMailer.auction_notification_mail(item, auction).deliver_later(wait_until: auction.starts_at)
WishlistMailer.auction_notification_mail(item, auction)
.deliver_later(wait_until: auction.starts_at)
WishlistAutoOfferJob.set(wait_until: auction.starts_at).perform_later(auction.id)
item.update(processed: true)
end
end

def self.wait_time
Rails.env.production? ? LONG_WAIT_TIME : SHORT_WAIT_TIME
end
end
3 changes: 1 addition & 2 deletions app/models/registry/auction_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ def indicate_correct_platform_and_assign_it(domain_name)
end

def send_wishlist_notifications(domain_name, remote_id)
WishlistJob.set(wait: WishlistJob.wait_time)
.perform_later(domain_name, remote_id)
WishlistJob.perform_later(domain_name, remote_id)
end

def destroy_autobider(domain_name)
Expand Down
10 changes: 0 additions & 10 deletions test/jobs/wishlist_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ def test_it_does_not_send_an_email_when_there_is_no_wishlist_item
end
end

def test_wait_time
assert_equal(1.minute, WishlistJob.wait_time)
mock = MiniTest::Mock.new
mock.expect(:production?, true)

Rails.stub(:env, mock) do
assert_equal(2.hours, WishlistJob.wait_time)
end
end

def test_schedules_auto_offer_job_and_only_once_when_there_is_a_wishlist_item
WishlistItem.create!(user: @user, domain_name: @auction.domain_name)

Expand Down

0 comments on commit 73d86ef

Please sign in to comment.