Skip to content

Commit

Permalink
Automatically set the ads based on the winners for the month
Browse files Browse the repository at this point in the history
  • Loading branch information
amree committed Oct 17, 2024
1 parent bda783c commit 54087e1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
18 changes: 18 additions & 0 deletions app/workers/update_ads_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class UpdateAdsWorker < SidekiqWorker
def perform
slugs_for_ads =
Bid
.joins(:auction)
.where("auctions.period = ?", Time.current.strftime("%Y-%m"))
.includes(:coffee_shop)
.order(amount: :desc, created_at: :asc)
.limit(2)
.pluck("coffee_shops.slug")
.join(",")

Rails.cache.write("ads/gold", slugs_for_ads)

TelegramNotifierWorker
.perform_async("Updated ads for the month: #{slugs_for_ads}")
end
end
4 changes: 4 additions & 0 deletions config/schedule.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
sitemap_refresh:
cron: "0 0 * * *"
class: "SitemapRefreshWorker"

sitemap_refresh:
cron: "5 0 1 * *"
class: "UpdateAdsWorker"
6 changes: 6 additions & 0 deletions db/migrate/20241017040725_add_period_to_auctions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddPeriodToAuctions < ActiveRecord::Migration[7.1]
def change
add_column :auctions, :period, :string
add_index :auctions, :period, unique: true
end
end
6 changes: 3 additions & 3 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 54087e1

Please sign in to comment.