Skip to content

Commit

Permalink
Merge pull request #891 from senid231/820-calls_monitoring_future_calls
Browse files Browse the repository at this point in the history
calls monitoring future calls calculation
  • Loading branch information
dmitry-sinina authored Feb 18, 2021
2 parents fd63e07 + 54ff49b commit cabecf2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 4 additions & 1 deletion app/jobs/jobs/calls_monitoring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
module Jobs
class CallsMonitoring < ::BaseJob
class CallCollection
MONITORING_INTERVAL = 60

attr_reader :collection,
:key,
:balance, :min_balance, :max_balance
Expand Down Expand Up @@ -83,7 +85,8 @@ def balance_after_calls
def call_price(attrs)
i_per_second_rate = attrs.fetch("#{key}_initial_rate").to_f / 60.0
n_per_second_rate = attrs.fetch("#{key}_next_rate").to_f / 60.0
duration = attrs.fetch('duration').to_i # TODO: check if needed cast to int
# duration that will be on next calls monitoring run
duration = attrs.fetch('duration').to_i + MONITORING_INTERVAL # TODO: check if needed cast to int
initial_interval = attrs.fetch("#{key}_initial_interval").to_i # TODO: check if needed cast to int
next_interval = attrs.fetch("#{key}_next_interval").to_i # TODO: check if needed cast to int
connect_fee = attrs.fetch("#{key}_fee").to_f
Expand Down
7 changes: 4 additions & 3 deletions spec/models/jobs/jobs/calls_monitoring_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
account_originated: 2,
account_originated_unique_src: 2,
account_originated_unique_dst: 2,
account_price_originated: -3.98,
account_price_originated: -3.96, # +1.04 normal call -5 reverse call
metric_labels: {
account_id: account.id,
account_external_id: account.external_id
Expand All @@ -212,7 +212,7 @@
.with(
type: 'yeti_ac',
account_terminated: 2,
account_price_terminated: 5.0,
account_price_terminated: 5.0, # +9 normal call -4 reverse call
metric_labels: {
account_id: vendor_acc.id,
account_external_id: vendor_acc.external_id
Expand Down Expand Up @@ -262,7 +262,8 @@
super().select { |c| c['local_tag'] == 'normal-call' }
end
let(:account_balance) do
1.02
# active calls cost on next calls monitoring run (after 1 min)
2.04 # 1.02 * 2
end

include_examples :keep_calls
Expand Down

0 comments on commit cabecf2

Please sign in to comment.