Skip to content

Commit 163fcfe

Browse files
committed
more logging of event fires
1 parent aa5d2c8 commit 163fcfe

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

campaigns/worker.go

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func fireEventFires(ctx context.Context, db *sqlx.DB, rp *redis.Pool, task *queu
9292
sessions, err := runner.FireCampaignEvent(ctx, db, rp, eventTask.OrgID, contactIDs, eventTask.FlowUUID, &event)
9393

9494
// TODO: optimize into a single query
95+
start := time.Now()
9596
for _, session := range sessions {
9697
fire, found := contactMap[session.ContactID]
9798

@@ -108,6 +109,7 @@ func fireEventFires(ctx context.Context, db *sqlx.DB, rp *redis.Pool, task *queu
108109
log.WithField("contact_id", session.ContactID).Errorf("unable to find session for contact id")
109110
}
110111
}
112+
log.WithField("elapsed", time.Since(start)).Info("event fires marked as complete")
111113

112114
// what remains in our contact map are fires that failed for some reason, umark these
113115
if len(contactMap) > 0 {

runner/runner.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,13 @@ func FireCampaignEvent(
8282

8383
// StartFlow runs the passed in flow for the passed in contact
8484
func StartFlow(ctx context.Context, db *sqlx.DB, rp *redis.Pool, org *models.OrgAssets, assets flows.SessionAssets, tgs []flows.Trigger) ([]*models.Session, error) {
85+
if len(tgs) == 0 {
86+
return nil, nil
87+
}
88+
8589
track := models.NewTrack(ctx, db, rp, org)
8690
start := time.Now()
91+
log := logrus.WithField("flow_name", tgs[0].Flow().Name).WithField("flow_uuid", tgs[0].Flow().UUID)
8792

8893
// for each trigger start the flow
8994
sessions := make([]flows.Session, 0, len(tgs))
@@ -92,12 +97,14 @@ func StartFlow(ctx context.Context, db *sqlx.DB, rp *redis.Pool, org *models.Org
9297
session := engine.NewSession(assets, engine.NewDefaultConfig(), httpClient)
9398

9499
// start our flow
100+
log := logrus.WithField("contact_uuid", trigger.Contact().UUID())
95101
start := time.Now()
96102
err := session.Start(trigger, nil)
97103
if err != nil {
98-
logrus.WithField("contact_id", trigger.Contact().ID()).WithError(err).Errorf("error starting flow: %s", trigger.Flow().UUID)
104+
log.WithError(err).Errorf("error starting flow")
99105
continue
100106
}
107+
log.WithField("elapsed", time.Since(start)).Info("flow engine start")
101108
librato.Gauge("mr.flow_start_elapsed", float64(time.Since(start)))
102109

103110
sessions = append(sessions, session)
@@ -177,6 +184,7 @@ func StartFlow(ctx context.Context, db *sqlx.DB, rp *redis.Pool, org *models.Org
177184
// figure out both average and total for total execution and commit time for our flows
178185
librato.Gauge("mr.flow_start_elapsed", float64(time.Since(start))/float64(time.Second))
179186
librato.Gauge("mr.flow_start_count", float64(len(dbSessions)))
187+
log.WithField("elapsed", time.Since(start)).WithField("count", len(dbSessions)).Info("flows started, sessions created")
180188

181189
return dbSessions, nil
182190
}

0 commit comments

Comments
 (0)