2026-01-21 03:30:03 +00:00
|
|
|
package background
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2026-02-08 04:01:48 +00:00
|
|
|
"fmt"
|
2026-05-22 23:19:31 +00:00
|
|
|
"strconv"
|
2026-03-18 15:36:20 +00:00
|
|
|
"time"
|
2026-01-23 20:36:16 +00:00
|
|
|
|
2026-05-22 23:19:31 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2026-05-19 15:33:57 +00:00
|
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/db"
|
|
|
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/public/model"
|
|
|
|
|
query "source.gleipnir.technology/Gleipnir/nidus-sync/db/query/public"
|
2026-01-21 03:30:03 +00:00
|
|
|
)
|
|
|
|
|
|
2026-05-22 23:19:31 +00:00
|
|
|
func NewAudioTranscode(ctx context.Context, txn db.Ex, audio_id int32) error {
|
|
|
|
|
return newJob(ctx, txn, model.Jobtype_AudioTranscode, audio_id)
|
2026-01-21 03:30:03 +00:00
|
|
|
}
|
2026-05-07 16:38:42 +00:00
|
|
|
func NewComplianceMailer(ctx context.Context, txn db.Ex, compliance_report_request_id int32) error {
|
2026-05-22 23:19:31 +00:00
|
|
|
return newJob(ctx, txn, model.Jobtype_ComplianceMailerSend, compliance_report_request_id)
|
2026-04-16 17:15:20 +00:00
|
|
|
}
|
2026-05-22 23:19:31 +00:00
|
|
|
func NewCSVCommit(ctx context.Context, txn db.Ex, csv_id int32) error {
|
|
|
|
|
return newJob(ctx, txn, model.Jobtype_CsvCommit, csv_id)
|
2026-01-21 03:30:03 +00:00
|
|
|
}
|
2026-05-22 23:19:31 +00:00
|
|
|
func NewCSVImport(ctx context.Context, txn db.Ex, csv_id int32) error {
|
|
|
|
|
return newJob(ctx, txn, model.Jobtype_CsvImport, csv_id)
|
2026-03-16 19:52:29 +00:00
|
|
|
}
|
2026-05-22 23:19:31 +00:00
|
|
|
func NewEmailSend(ctx context.Context, txn db.Ex, email_id int32) error {
|
|
|
|
|
return newJob(ctx, txn, model.Jobtype_EmailSend, email_id)
|
2026-03-16 19:52:29 +00:00
|
|
|
}
|
2026-05-22 23:19:31 +00:00
|
|
|
func NewLabelStudioAudioCreate(ctx context.Context, txn db.Ex, note_audio_id int32) error {
|
|
|
|
|
return newJob(ctx, txn, model.Jobtype_LabelStudioAudioCreate, note_audio_id)
|
2026-03-16 19:52:29 +00:00
|
|
|
}
|
2026-05-22 15:13:03 +00:00
|
|
|
func NewTextRespond(ctx context.Context, txn db.Ex, text_id int32) error {
|
2026-05-22 23:19:31 +00:00
|
|
|
return newJob(ctx, txn, model.Jobtype_TextRespond, text_id)
|
2026-03-18 15:36:20 +00:00
|
|
|
}
|
2026-05-15 16:58:28 +00:00
|
|
|
func NewTextSend(ctx context.Context, txn db.Ex, job_id int32) error {
|
2026-05-22 23:19:31 +00:00
|
|
|
return newJob(ctx, txn, model.Jobtype_TextSend, job_id)
|
2026-03-16 19:52:29 +00:00
|
|
|
}
|
2026-05-22 23:19:31 +00:00
|
|
|
func newJob(ctx context.Context, txn db.Ex, t model.Jobtype, id int32) error {
|
2026-05-07 16:38:42 +00:00
|
|
|
job := model.Job{
|
|
|
|
|
Created: time.Now(),
|
|
|
|
|
Type: t,
|
|
|
|
|
RowID: id,
|
|
|
|
|
}
|
2026-05-22 23:19:31 +00:00
|
|
|
j, err := query.JobInsert(ctx, txn, job)
|
2026-05-07 16:38:42 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("insert job: %w", err)
|
|
|
|
|
}
|
2026-05-22 23:19:31 +00:00
|
|
|
err = query.JobNotify(ctx, txn, "new_job", strconv.Itoa(int(j.ID)))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("notify job: %w", err)
|
|
|
|
|
}
|
|
|
|
|
log.Debug().Int32("id", j.ID).Int32("row_id", id).Msg("created job, added notify")
|
2026-05-07 16:38:42 +00:00
|
|
|
return nil
|
|
|
|
|
}
|