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.
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package platform
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/db"
|
|
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
|
"github.com/google/uuid"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func NoteAudioCreate(ctx context.Context, user User, setter models.NoteAudioSetter) error {
|
|
_, err := models.Organizations.Insert(&setter).One(ctx, db.PGInstance.BobDB)
|
|
if err != nil {
|
|
// Just ignore this failure, it means we already have this content
|
|
if err.Error() != "insertOrganizationNoteAudios0: ERROR: duplicate key value violates unique constraint \"note_audio_pkey\" (SQLSTATE 23505)" {
|
|
return fmt.Errorf("create note_audio: %w", err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func NoteAudioNormalized(uuid string) error {
|
|
return nil
|
|
}
|
|
func NoteAudioTranscodedToOgg(uuid string) error {
|
|
return nil
|
|
}
|
|
func NoteImageCreate(ctx context.Context, user User, setter models.NoteImageSetter) error {
|
|
err := user.Organization.model.InsertNoteImages(ctx, db.PGInstance.BobDB, &setter)
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
// Just ignore this failure, it means we already have this content
|
|
if err.Error() == "insertOrganizationNoteImages0: ERROR: duplicate key value violates unique constraint \"note_image_pkey\" (SQLSTATE 23505)" {
|
|
return nil
|
|
}
|
|
log.Warn().Err(err).Msg("Unrecognized error creating note audio")
|
|
return err
|
|
}
|
|
|
|
func NoteUpdate(ctx context.Context, noteUUID uuid.UUID, setter models.NoteAudioSetter) error {
|
|
return nil
|
|
}
|