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
# the stripe property in the user with what's being stored in Stripe.
log = require 'winston'
MongoClient = require('mongodb').MongoClient
mongoose = require 'mongoose'
async = require 'async'
@ -90,10 +91,15 @@ class SubscriptionHandler extends Handler
userMap = {}
userMap[user.id] = user.toObject() for user in users
try
# 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}"
log.debug "Analytics url: #{url}"
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 = {}
db.collection('log').find({user: {$in: subscriberUserIDs}}).sort({_id: -1}).each (err, doc) =>
if err
@ -103,6 +109,7 @@ class SubscriptionHandler extends Handler
userEventMap[doc.user] ?= []
userEventMap[doc.user].push doc
else
log.debug 'Analytics finished received docs, closing db connection. ' + Object.keys(userEventMap).length
db.close()
for userID, eventList of userEventMap
finishedPurchase = false
@ -116,6 +123,9 @@ class SubscriptionHandler extends Handler
userMap[userID].conversion = event.properties.label
break
@sendSuccess(res, userMap)
catch err
log.debug 'Analytics error:\n' + err
@sendSuccess(res, userMap)
getSubscriptions: (req, res) ->
# console.log 'subscription_handler getSubscriptions'