The goal of this rework is to make it so I can pass around platform.User instead of a pair of models.Organization and models.User. This is useful for reason I kind of forget now, but it started with working on notifications and ballooned massively from there into refactoring a number of things that were bugging me. This also includes a tiny amount of work on server-side events (SSE). * background stuff lives inside the platform now, which I need for having it push updates through SSE * userfile now lives in the platform, under file, so other platform functions can safely use it * oauth is broken into pieces and inside platform because other stuff was calling it already, but badly. * notifications go into the platform as well
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package background
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/platform/subprocess"
|
|
"github.com/google/uuid"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
// AudioJob represents a job to process an audio file.
|
|
type jobAudio struct {
|
|
AudioUUID uuid.UUID
|
|
}
|
|
|
|
var channelJobAudio chan jobAudio
|
|
|
|
func AudioTranscode(audio_uuid uuid.UUID) {
|
|
enqueueAudioJob(jobAudio{
|
|
AudioUUID: audio_uuid,
|
|
})
|
|
}
|
|
|
|
// startAudioWorker initializes the audio job channel and starts the worker goroutine.
|
|
func startWorkerAudio(ctx context.Context, audioJobChannel chan jobAudio) {
|
|
go func() {
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
log.Info().Msg("Audio worker shutting down.")
|
|
return
|
|
case job := <-audioJobChannel:
|
|
log.Info().Str("uuid", job.AudioUUID.String()).Msg("Processing audio job")
|
|
err := processAudioFile(job.AudioUUID)
|
|
if err != nil {
|
|
log.Error().Err(err).Str("uuid", job.AudioUUID.String()).Msg("Error processing audio file")
|
|
}
|
|
}
|
|
}
|
|
}()
|
|
}
|
|
|
|
// EnqueueAudioJob sends an audio processing job to the worker.
|
|
func enqueueAudioJob(job jobAudio) {
|
|
select {
|
|
case channelJobAudio <- job:
|
|
log.Info().Str("uuid", job.AudioUUID.String()).Msg("Enqueued audio job")
|
|
default:
|
|
log.Warn().Str("uuid", job.AudioUUID.String()).Msg("Audio job channel is full, dropping job")
|
|
}
|
|
}
|
|
|
|
func processAudioFile(audioUUID uuid.UUID) error {
|
|
// Normalize audio
|
|
err := subprocess.NormalizeAudio(audioUUID)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to normalize audio %s: %v", audioUUID, err)
|
|
}
|
|
|
|
// Transcode to OGG
|
|
err = subprocess.TranscodeToOgg(audioUUID)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to transcode audio %s to OGG: %v", audioUUID, err)
|
|
}
|
|
|
|
enqueueLabelStudioJob(jobLabelStudio{
|
|
UUID: audioUUID,
|
|
})
|
|
return nil
|
|
}
|