From 8601480a3cee87223cdcb7564bc00e4c67cc2e88 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Thu, 2 Sep 2021 15:32:06 -0500 Subject: [PATCH] Read sessions from db or s3 depending on whether output_url is set --- core/models/runs.go | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/core/models/runs.go b/core/models/runs.go index 96cc7118e..b5f61d273 100644 --- a/core/models/runs.go +++ b/core/models/runs.go @@ -429,34 +429,28 @@ func ActiveSessionForContact(ctx context.Context, db *sqlx.DB, st storage.Storag contact: contact, } session.scene = NewSceneForSession(session) - err = rows.StructScan(&session.s) - if err != nil { + + if err := rows.StructScan(&session.s); err != nil { return nil, errors.Wrapf(err, "error scanning session") } - // load our output if necessary - if org.Org().SessionStorageMode() == S3Sessions && session.OutputURL() != "" { - start := time.Now() - + // load our output from storage if necessary + if session.OutputURL() != "" { // strip just the path out of our output URL u, err := url.Parse(session.OutputURL()) if err != nil { return nil, errors.Wrapf(err, "error parsing output URL: %s", session.OutputURL()) } - // get our session from storage + start := time.Now() + _, output, err := st.Get(ctx, u.Path) if err != nil { - logrus.WithField("output_url", session.OutputURL()).WithField("org_id", org.OrgID()).WithField("session_uuid", session.UUID()).WithError(err).Error("error reading in session output from storage") - - // we'll throw an error up only if we don't have a DB backdown - if session.Output() == "" { - return nil, errors.Wrapf(err, "error reading session from storage: %s", session.OutputURL()) - } - } else { - session.s.Output = null.String(output) - logrus.WithField("elapsed", time.Since(start)).WithField("output_url", session.OutputURL()).Debug("loaded session from storage") + return nil, errors.Wrapf(err, "error reading session from storage: %s", session.OutputURL()) } + + logrus.WithField("elapsed", time.Since(start)).WithField("output_url", session.OutputURL()).Debug("loaded session from storage") + session.s.Output = null.String(output) } return session, nil