Add debug logging to recent subs API

Unclear why this isn’t working in production.
This commit is contained in:
Matt Lott 2015-05-01 11:08:17 -07:00
parent 5305d80887
commit 1ac249565a

View file

@ -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,10 +91,15 @@ class SubscriptionHandler extends Handler
userMap = {} userMap = {}
userMap[user.id] = user.toObject() for user in users userMap[user.id] = user.toObject() for user in users
try
# Get conversion data directly from analytics database and add it to results # Get conversion data directly from analytics database and add it to results
url = "mongodb://#{config.mongo.analytics_host}:#{config.mongo.analytics_port}/#{config.mongo.analytics_db}" url = "mongodb://#{config.mongo.analytics_host}:#{config.mongo.analytics_port}/#{config.mongo.analytics_db}"
log.debug "Analytics url: #{url}"
MongoClient.connect url, (err, db) => MongoClient.connect url, (err, db) =>
return @sendDatabaseError(res, err) if err if err
log.debug 'Analytics connect error: ' + err
return @sendDatabaseError(res, err)
log.debug 'Analytics established connection to analytics server.'
userEventMap = {} userEventMap = {}
db.collection('log').find({user: {$in: subscriberUserIDs}}).sort({_id: -1}).each (err, doc) => db.collection('log').find({user: {$in: subscriberUserIDs}}).sort({_id: -1}).each (err, doc) =>
if err if err
@ -103,6 +109,7 @@ class SubscriptionHandler extends Handler
userEventMap[doc.user] ?= [] userEventMap[doc.user] ?= []
userEventMap[doc.user].push doc userEventMap[doc.user].push doc
else else
log.debug 'Analytics finished received docs, closing db connection. ' + Object.keys(userEventMap).length
db.close() db.close()
for userID, eventList of userEventMap for userID, eventList of userEventMap
finishedPurchase = false finishedPurchase = false
@ -116,6 +123,9 @@ class SubscriptionHandler extends Handler
userMap[userID].conversion = event.properties.label userMap[userID].conversion = event.properties.label
break break
@sendSuccess(res, userMap) @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'