nidus-sync/platform/audio.go
Eli Ribble 2538638c9d
Create generic backend process, fix background interdependencies
This refactor was born out of the inter-dependency cycles developing
between the "background" module and just about every other module which
was caused by the background module becoming a dependency of every
module that needed to background work and the fact that the background
module was also supposedly responsible for the logic for processing
those tasks.

Instead the "background" module is now very, very shallow and relies
entirely on the Postgres NOTIFY logic for triggering jobs. There's a new
table, `job` which holds just a type and single row ID.

All told, this means that jobs can be added to the queue as part of the
API-level or platform-level transaction, ensuring atomicity, and
processing coordination is handled by the platform module, which can
depend on anything.
2026-03-16 19:52:29 +00:00

38 lines
1 KiB
Go

package platform
import (
"context"
"fmt"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/Gleipnir-Technology/nidus-sync/platform/background"
"github.com/Gleipnir-Technology/nidus-sync/platform/subprocess"
//"github.com/google/uuid"
//"github.com/rs/zerolog/log"
)
func processAudioFile(ctx context.Context, txn bob.Executor, audio_id int32) error {
a, err := models.NoteAudios.Query(
models.SelectWhere.NoteAudios.ID.EQ(audio_id),
).One(ctx, db.PGInstance.BobDB)
if err != nil {
return fmt.Errorf("note audio query: %w", err)
}
// Normalize audio
err = subprocess.NormalizeAudio(a.UUID)
if err != nil {
return fmt.Errorf("failed to normalize audio %s: %v", a.UUID, err)
}
// Transcode to OGG
err = subprocess.TranscodeToOgg(a.UUID)
if err != nil {
return fmt.Errorf("failed to transcode audio %s to OGG: %v", a.UUID, err)
}
background.NewLabelStudioAudioCreate(ctx, db.PGInstance.BobDB, audio_id)
return nil
}