monitor first charge of patron
parent
fe615b8d3a
commit
6c1c62b9de
|
@ -405,11 +405,12 @@ object mon {
|
|||
val json = future("swiss.json")
|
||||
}
|
||||
object plan {
|
||||
val paypal = histogram("plan.amount").withTag("service", "paypal")
|
||||
val stripe = histogram("plan.amount").withTag("service", "stripe")
|
||||
val goal = gauge("plan.goal").withoutTags()
|
||||
val current = gauge("plan.current").withoutTags()
|
||||
val percent = gauge("plan.percent").withoutTags()
|
||||
val paypal = histogram("plan.amount").withTag("service", "paypal")
|
||||
val stripe = histogram("plan.amount").withTag("service", "stripe")
|
||||
val goal = gauge("plan.goal").withoutTags()
|
||||
val current = gauge("plan.current").withoutTags()
|
||||
val percent = gauge("plan.percent").withoutTags()
|
||||
def firstCharge(service: String) = counter("plan.charge.first").withTag("service", service)
|
||||
}
|
||||
object forum {
|
||||
object post {
|
||||
|
|
|
@ -347,23 +347,32 @@ final class PlanApi(
|
|||
}
|
||||
|
||||
private def addCharge(charge: Charge): Funit =
|
||||
chargeColl.insert.one(charge).void >>- {
|
||||
recentChargeUserIdsCache.invalidateUnit()
|
||||
monthlyGoalApi.get foreach { m =>
|
||||
Bus.publish(
|
||||
lila.hub.actorApi.plan.ChargeEvent(
|
||||
username = charge.userId.flatMap(lightUserApi.sync).fold("Anonymous")(_.name),
|
||||
amount = charge.cents.value,
|
||||
percent = m.percent,
|
||||
DateTime.now
|
||||
),
|
||||
"plan"
|
||||
)
|
||||
lila.mon.plan.goal.update(m.goal.value)
|
||||
lila.mon.plan.current.update(m.current.value)
|
||||
lila.mon.plan.percent.update(m.percent)
|
||||
if (charge.isPayPal) lila.mon.plan.paypal.record(charge.cents.value)
|
||||
else if (charge.isStripe) lila.mon.plan.stripe.record(charge.cents.value)
|
||||
monitorFirstCharge(charge) >>
|
||||
chargeColl.insert.one(charge).void >>- {
|
||||
recentChargeUserIdsCache.invalidateUnit()
|
||||
monthlyGoalApi.get foreach { m =>
|
||||
Bus.publish(
|
||||
lila.hub.actorApi.plan.ChargeEvent(
|
||||
username = charge.userId.flatMap(lightUserApi.sync).fold("Anonymous")(_.name),
|
||||
amount = charge.cents.value,
|
||||
percent = m.percent,
|
||||
DateTime.now
|
||||
),
|
||||
"plan"
|
||||
)
|
||||
lila.mon.plan.goal.update(m.goal.value)
|
||||
lila.mon.plan.current.update(m.current.value)
|
||||
lila.mon.plan.percent.update(m.percent)
|
||||
if (charge.isPayPal) lila.mon.plan.paypal.record(charge.cents.value)
|
||||
else if (charge.isStripe) lila.mon.plan.stripe.record(charge.cents.value)
|
||||
}
|
||||
}
|
||||
|
||||
private def monitorFirstCharge(charge: Charge): Funit =
|
||||
charge.userId ?? { userId =>
|
||||
chargeColl.exists($doc("userId" -> userId)) map {
|
||||
case false => lila.mon.plan.newPatron(charge.serviceName).increment().unit
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue