Manager: store task logs to disk

This commit is contained in:
Sybren A. Stüvel 2022-02-21 19:47:07 +01:00
parent 5b0e11acdc
commit 90a2140b8c
4 changed files with 18 additions and 4 deletions

1
.gitignore vendored

@ -5,3 +5,4 @@
/flamenco-worker.yaml
/flamenco-worker-credentials.yaml
node_modules/
task-logs/

@ -45,6 +45,7 @@ type Flamenco struct {
type PersistenceService interface {
StoreAuthoredJob(ctx context.Context, authoredJob job_compilers.AuthoredJob) error
FetchJob(ctx context.Context, jobID string) (*persistence.Job, error)
// FetchTask fetches the given task and the accompanying job.
FetchTask(ctx context.Context, taskID string) (*persistence.Task, error)
SaveTask(ctx context.Context, task *persistence.Task) error

@ -180,6 +180,10 @@ func (f *Flamenco) doTaskUpdate(
dbTask *persistence.Task,
update api.TaskUpdateJSONRequestBody,
) error {
if dbTask.Job == nil {
logger.Panic().Msg("dbTask.Job is nil, unable to continue")
}
if update.TaskStatus != nil {
// TODO: check that this status transition is valid.
// TODO: process this status transition.
@ -195,10 +199,18 @@ func (f *Flamenco) doTaskUpdate(
dbTask.Activity = *update.Activity
}
// Do the database persistence first, as that's more important than the logging.
dbErr := f.persist.SaveTask(ctx, dbTask)
if update.Log != nil {
// TODO: write log to disk.
logger.Warn().Msg("task logs are not yet handled")
// Errors writing the log to file should be logged in our own logging
// system, but shouldn't abort the render. As such, `err` is not returned to
// the caller.
err := f.logStorage.Write(logger, dbTask.Job.UUID, dbTask.UUID, *update.Log)
if err != nil {
logger.Error().Err(err).Msg("error writing task log")
}
}
return f.persist.SaveTask(ctx, dbTask)
return dbErr
}

@ -205,7 +205,7 @@ func (db *DB) SaveJobStatus(ctx context.Context, j *Job) error {
func (db *DB) FetchTask(ctx context.Context, taskUUID string) (*Task, error) {
dbTask := Task{}
findResult := db.gormDB.First(&dbTask, "uuid = ?", taskUUID)
findResult := db.gormDB.Joins("Job").First(&dbTask, "tasks.uuid = ?", taskUUID)
if findResult.Error != nil {
return nil, findResult.Error
}