Files
LazyPM/pkg/task/lifecycle.go
Robin Olsen 72a2e8acf5 Metrics and logs - MongoDB Submission (#43)
Adds MongoDB-backed submission for survey statistics/metrics and introduces MongoDB ObjectID-based participant/task identifiers to support upserts and linking metrics to a participant.

It introduces breaking changes to the exsisting json stat and metric files. Delete the old ones

Changes:

Add internal/storage/MongoStorage and wire pm survey submit / pm start to submit local .pm/*.json files to MongoDB.
Extend stats/metrics models to include MongoDB _id / participant_id fields and add participant ID propagation into task metrics.
Update app initialization to generate ObjectIDs for new participants and expose GetParticipantID() via StatsService.
2026-03-10 14:09:31 +01:00

43 lines
1.0 KiB
Go

package task
import (
"log/slog"
"github.com/LazyBachelor/LazyPM/internal/models"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type RunLifecycle struct {
collector *taskRunCollector
config Config
details models.TaskDetails
app *App
logger *slog.Logger
metricsStore MetricsStore
}
func NewRunLifecycle(app *App, config Config, details models.TaskDetails, iType InterfaceType, logger *slog.Logger) *RunLifecycle {
collector := newTaskRunCollector(details.Title, iType, logger)
config = config.WithActionLogger(func(action string) {
collector.recordUserAction(action)
})
var participantID primitive.ObjectID
var store MetricsStore
if config.StatisticsStoragePath != "" {
participantID = app.Stats.GetParticipantID()
store = NewFileMetricsStore(config.StatisticsStoragePath, participantID, logger)
}
return &RunLifecycle{
collector: collector,
config: config,
details: details,
app: app,
logger: logger,
metricsStore: store,
}
}