mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 01:55:38 -05:00
Add debug logging to recent subs API
Unclear why this isn’t working in production.
This commit is contained in:
parent
5305d80887
commit
1ac249565a
1 changed files with 34 additions and 24 deletions
|
@ -1,6 +1,7 @@
|
||||||
# Not paired with a document in the DB, just handles coordinating between
|
# Not paired with a document in the DB, just handles coordinating between
|
||||||
# the stripe property in the user with what's being stored in Stripe.
|
# the stripe property in the user with what's being stored in Stripe.
|
||||||
|
|
||||||
|
log = require 'winston'
|
||||||
MongoClient = require('mongodb').MongoClient
|
MongoClient = require('mongodb').MongoClient
|
||||||
mongoose = require 'mongoose'
|
mongoose = require 'mongoose'
|
||||||
async = require 'async'
|
async = require 'async'
|
||||||
|
@ -90,32 +91,41 @@ class SubscriptionHandler extends Handler
|
||||||
userMap = {}
|
userMap = {}
|
||||||
userMap[user.id] = user.toObject() for user in users
|
userMap[user.id] = user.toObject() for user in users
|
||||||
|
|
||||||
# Get conversion data directly from analytics database and add it to results
|
try
|
||||||
url = "mongodb://#{config.mongo.analytics_host}:#{config.mongo.analytics_port}/#{config.mongo.analytics_db}"
|
# Get conversion data directly from analytics database and add it to results
|
||||||
MongoClient.connect url, (err, db) =>
|
url = "mongodb://#{config.mongo.analytics_host}:#{config.mongo.analytics_port}/#{config.mongo.analytics_db}"
|
||||||
return @sendDatabaseError(res, err) if err
|
log.debug "Analytics url: #{url}"
|
||||||
userEventMap = {}
|
MongoClient.connect url, (err, db) =>
|
||||||
db.collection('log').find({user: {$in: subscriberUserIDs}}).sort({_id: -1}).each (err, doc) =>
|
|
||||||
if err
|
if err
|
||||||
db.close()
|
log.debug 'Analytics connect error: ' + err
|
||||||
return @sendDatabaseError(res, err)
|
return @sendDatabaseError(res, err)
|
||||||
if (doc)
|
log.debug 'Analytics established connection to analytics server.'
|
||||||
userEventMap[doc.user] ?= []
|
userEventMap = {}
|
||||||
userEventMap[doc.user].push doc
|
db.collection('log').find({user: {$in: subscriberUserIDs}}).sort({_id: -1}).each (err, doc) =>
|
||||||
else
|
if err
|
||||||
db.close()
|
db.close()
|
||||||
for userID, eventList of userEventMap
|
return @sendDatabaseError(res, err)
|
||||||
finishedPurchase = false
|
if (doc)
|
||||||
for event in eventList
|
userEventMap[doc.user] ?= []
|
||||||
finishedPurchase = true if event.event is 'Finished subscription purchase'
|
userEventMap[doc.user].push doc
|
||||||
if finishedPurchase
|
else
|
||||||
if event.event is 'Show subscription modal' and event.properties?.level?
|
log.debug 'Analytics finished received docs, closing db connection. ' + Object.keys(userEventMap).length
|
||||||
userMap[userID].conversion = event.properties.level
|
db.close()
|
||||||
break
|
for userID, eventList of userEventMap
|
||||||
else if event.event is 'Show subscription modal' and event.properties?.label is 'buy gems modal'
|
finishedPurchase = false
|
||||||
userMap[userID].conversion = event.properties.label
|
for event in eventList
|
||||||
break
|
finishedPurchase = true if event.event is 'Finished subscription purchase'
|
||||||
@sendSuccess(res, userMap)
|
if finishedPurchase
|
||||||
|
if event.event is 'Show subscription modal' and event.properties?.level?
|
||||||
|
userMap[userID].conversion = event.properties.level
|
||||||
|
break
|
||||||
|
else if event.event is 'Show subscription modal' and event.properties?.label is 'buy gems modal'
|
||||||
|
userMap[userID].conversion = event.properties.label
|
||||||
|
break
|
||||||
|
@sendSuccess(res, userMap)
|
||||||
|
catch err
|
||||||
|
log.debug 'Analytics error:\n' + err
|
||||||
|
@sendSuccess(res, userMap)
|
||||||
|
|
||||||
getSubscriptions: (req, res) ->
|
getSubscriptions: (req, res) ->
|
||||||
# console.log 'subscription_handler getSubscriptions'
|
# console.log 'subscription_handler getSubscriptions'
|
||||||
|
|
Loading…
Reference in a new issue