auctify 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14832525cab9835407bccb94056500037fe39da17a9ea311f7053ce4adf48255
4
- data.tar.gz: 522647a33fa236dd02c2980ecde719508bd83f21db2c0ffa38d1d77ce104d002
3
+ metadata.gz: bff579c105985a8f250d586936aa3ff93dbf1d0fe3b378c69b1ca91cd54e8dbe
4
+ data.tar.gz: 40a062694ac56b79ff884ec3cb233c4647881d365f76fee944da6ba0c88ceee4
5
5
  SHA512:
6
- metadata.gz: 803112a2c554cb95f1eb818911ea4a92d4377306ba936ac5190101f8463a5378d225a5c260a50e01e8cc0f379ddd87b1d57902d186a8469c7baa34dee991f23a
7
- data.tar.gz: ee8f293dbba3adc69a730d208b4973ebf7d9609d326bca03eda616ca668edfb792b2d4d9b09bef211a5c08db221da2befcd507d9d3f0844c5d8de1e774db46d8
6
+ metadata.gz: aab916ea0865c95cb54199b7ad1d807f3508dd87c6e94cebb8eed533b5e7f79e9f5d58132f65cebc14a3a8fc096073794e5df443e883d17a57c37eacb849e9d6
7
+ data.tar.gz: 814db09ba82b44e8c59981f0f439d7e39d2fe8df85c13c057ae167c0488989de7b5512ddb0473529398a2d10ff5108afc2151e261d83ae6699c0f0b0f7571a31
data/README.md CHANGED
@@ -221,7 +221,19 @@ end
221
221
 
222
222
  To protect accidential deletions, many associations are binded with `dependent: restrict_with_error`. Correct order ofdeletion is `bids` => `sales` => `sales_packs`.
223
223
 
224
-
224
+ ## Monitor it
225
+ Auctify should add some metrics for Prometheus (using Yabeda gem). Exposing them on `/metrics` path.
226
+ ```
227
+ group :auctify do
228
+ counter :bids_count, comment: "A counter of applied bids"
229
+ gauge :diff_in_closing_time_seconds,
230
+ comment: "Difference between auction.currently_ends_at and actual sale end time by job"
231
+ gauge :time_between_bids, comment: "Time period between last two bids", tags: [:auction_slug]
232
+ end
233
+ ```
234
+ See `lib/yabeda_config.rb` for current setup.
235
+ Note: `diff_in_closing_time_seconds` is fill in `auction.close_bidding!`. At normal setup this is done in background job, so value is maintained in BJ process not rails app.
236
+ Eg. if You use sidekiq for backgoud jobs, You will need `yabeda-sidekiq` gem and then value vwill be displayed at port 9394 (`your.app:9394/metrics`).
225
237
 
226
238
  ## Contributing
227
239
  Contribution directions go here.
@@ -2,5 +2,9 @@
2
2
 
3
3
  module Auctify
4
4
  class ApplicationJob < ActiveJob::Base
5
+ private
6
+ def auction_label(auction)
7
+ "[#{auction.try(:slug)}##{auction.id}; currently_ends_at: #{auction.currently_ends_at}]"
8
+ end
5
9
  end
6
10
  end
@@ -12,11 +12,14 @@ module Auctify
12
12
  return
13
13
  end
14
14
 
15
- return if Time.current < auction.currently_ends_at
16
-
17
- Auctify::Sale::Auction.with_advisory_lock("closing_auction_#{auction_id}") do
18
- # can wait unitl other BCJob release lock and than continue!
19
- auction.close_bidding! if auction.reload.in_sale?
15
+ if Time.current < auction.currently_ends_at
16
+ Rails.logger.info("Too soon for closing of auction #{auction_label(auction)}.")
17
+ else
18
+ Rails.logger.info("Closing auction #{auction_label(auction)} NOW!")
19
+ Auctify::Sale::Auction.with_advisory_lock("closing_auction_#{auction_id}") do
20
+ # can wait unitl other BCJob release lock and than continue!
21
+ auction.close_bidding! if auction.reload.in_sale?
22
+ end
20
23
  end
21
24
  end
22
25
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Auctify
4
- class EnsureAuctionsClosingJob < ApplicationJob
4
+ class EnsureAuctionsClosingJob < Auctify::ApplicationJob
5
5
  queue_as :critical
6
6
 
7
7
  def perform
@@ -9,8 +9,10 @@ module Auctify
9
9
  .where("currently_ends_at <= ?", Time.current + checking_period_to_future)
10
10
  auctions.each do |auction|
11
11
  if auction.currently_ends_at <= Time.current
12
+ Rails.logger.info("Queueing auction #{auction_label(auction)} for immediate close.")
12
13
  Auctify::BiddingCloserJob.perform_later(auction_id: auction.id)
13
14
  else
15
+ Rails.logger.info("Delaying close of auction #{auction_label(auction)}.")
14
16
  Auctify::BiddingCloserJob.set(wait_until: auction.currently_ends_at).perform_later(auction_id: auction.id)
15
17
  end
16
18
  end
@@ -69,7 +69,9 @@ module Auctify
69
69
 
70
70
  after do
71
71
  self.winner = current_winner
72
+
72
73
  now = Time.current
74
+ Yabeda.auctify.diff_in_closing_time_seconds.set({}, (now - self.currently_ends_at))
73
75
  self.currently_ends_at = now if now < currently_ends_at
74
76
 
75
77
  after_close_bidding
@@ -161,7 +163,16 @@ module Auctify
161
163
 
162
164
  bap = Auctify::BidsAppender.call(auction: self, bid: bid)
163
165
 
164
- bap.success? ? after_bid_appended(bap) : after_bid_not_appended(bap)
166
+ if bap.success?
167
+ after_bid_appended(bap)
168
+
169
+ Yabeda.auctify.bids_count.increment({}, by: 1)
170
+ times = ordered_applied_bids.limit(2).pluck(:created_at)
171
+ Yabeda.auctify.time_between_bids.set({ auction_slug: slug }, (times.size == 1 ? 0 : times.first - times.second))
172
+ else
173
+ after_bid_not_appended(bap)
174
+ end
175
+
165
176
  bap.success?
166
177
  end
167
178
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yabeda/prometheus"
4
+
5
+ module Auctify
6
+ class Railtie < Rails::Railtie
7
+ initializer "my_railtie.configure_rails_initialization" do |app|
8
+ app.middleware.use ::Yabeda::Prometheus::Exporter
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Auctify
4
- VERSION = "1.1.3"
4
+ VERSION = "1.1.4"
5
5
  end
data/lib/auctify.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ if defined?(Rails::Railtie)
4
+ require "auctify/railtie"
5
+ require "yabeda_config.rb"
6
+ end
7
+
3
8
  require "auctify/engine"
4
9
  require "auctify/configuration"
5
10
 
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yabeda/prometheus"
4
+
5
+ Yabeda.configure do
6
+ group :auctify do
7
+ counter :bids_count, comment: "A counter of applied bids"
8
+ gauge :diff_in_closing_time_seconds,
9
+ comment: "Difference between auction.currently_ends_at and actual sale end time by job"
10
+ gauge :time_between_bids, comment: "Time period between last two bids", tags: [:auction_slug]
11
+ end
12
+
13
+ collect do # when /metrics is displayed
14
+ # main_app.t_gauge.set({}, rand(10))
15
+ end
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auctify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - foton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-19 00:00:00.000000000 Z
11
+ date: 2022-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yabeda-prometheus
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: pg
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -428,8 +442,10 @@ files:
428
442
  - lib/auctify.rb
429
443
  - lib/auctify/configuration.rb
430
444
  - lib/auctify/engine.rb
445
+ - lib/auctify/railtie.rb
431
446
  - lib/auctify/version.rb
432
447
  - lib/tasks/auctify_tasks.rake
448
+ - lib/yabeda_config.rb
433
449
  homepage: https://github.com/sinfin/auctify
434
450
  licenses:
435
451
  - MIT