2026-01-21 03:30:03 +00:00
|
|
|
package background
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2026-02-08 04:01:48 +00:00
|
|
|
"fmt"
|
2026-03-18 15:36:20 +00:00
|
|
|
"time"
|
2026-01-23 20:36:16 +00:00
|
|
|
|
2026-03-16 19:52:29 +00:00
|
|
|
"github.com/Gleipnir-Technology/bob"
|
|
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
|
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
|
|
|
|
"github.com/aarondl/opt/omit"
|
|
|
|
|
//"github.com/rs/zerolog/log"
|
2026-01-21 03:30:03 +00:00
|
|
|
)
|
|
|
|
|
|
2026-03-16 19:52:29 +00:00
|
|
|
func NewAudioTranscode(ctx context.Context, txn bob.Executor, audio_id int32) error {
|
2026-03-19 20:14:23 +00:00
|
|
|
return newJob(ctx, txn, enums.JobtypeAudioTranscode, audio_id)
|
2026-01-21 03:30:03 +00:00
|
|
|
}
|
2026-04-16 17:15:20 +00:00
|
|
|
func NewComplianceMailer(ctx context.Context, txn bob.Executor, compliance_report_request_id int32) error {
|
|
|
|
|
return newJob(ctx, txn, enums.JobtypeComplianceMailerSend, compliance_report_request_id)
|
|
|
|
|
}
|
2026-03-16 19:52:29 +00:00
|
|
|
func NewCSVCommit(ctx context.Context, txn bob.Executor, csv_id int32) error {
|
|
|
|
|
return newJob(ctx, txn, enums.JobtypeCSVCommit, csv_id)
|
2026-01-21 03:30:03 +00:00
|
|
|
}
|
2026-03-16 19:52:29 +00:00
|
|
|
func NewCSVImport(ctx context.Context, txn bob.Executor, csv_id int32) error {
|
|
|
|
|
return newJob(ctx, txn, enums.JobtypeCSVImport, csv_id)
|
|
|
|
|
}
|
|
|
|
|
func NewEmailSend(ctx context.Context, txn bob.Executor, email_id int32) error {
|
|
|
|
|
return newJob(ctx, txn, enums.JobtypeEmailSend, email_id)
|
|
|
|
|
}
|
|
|
|
|
func NewLabelStudioAudioCreate(ctx context.Context, txn bob.Executor, note_audio_id int32) error {
|
|
|
|
|
return newJob(ctx, txn, enums.JobtypeLabelStudioAudioCreate, note_audio_id)
|
|
|
|
|
}
|
2026-03-18 15:36:20 +00:00
|
|
|
func NewTextRespond(ctx context.Context, txn bob.Executor, text_id int32) error {
|
|
|
|
|
return newJob(ctx, txn, enums.JobtypeTextRespond, text_id)
|
|
|
|
|
}
|
|
|
|
|
func NewTextSend(ctx context.Context, txn bob.Executor, job_id int32) error {
|
|
|
|
|
return newJob(ctx, txn, enums.JobtypeTextSend, job_id)
|
2026-03-16 19:52:29 +00:00
|
|
|
}
|
|
|
|
|
func newJob(ctx context.Context, txn bob.Executor, t enums.Jobtype, id int32) error {
|
|
|
|
|
_, err := models.Jobs.Insert(&models.JobSetter{
|
2026-03-18 15:36:20 +00:00
|
|
|
Created: omit.From(time.Now()),
|
2026-03-16 19:52:29 +00:00
|
|
|
// ID
|
|
|
|
|
Type: omit.From(t),
|
|
|
|
|
RowID: omit.From(id),
|
|
|
|
|
}).One(ctx, txn)
|
2026-03-04 19:02:11 +00:00
|
|
|
if err != nil {
|
2026-03-16 19:52:29 +00:00
|
|
|
return fmt.Errorf("insert job: %w", err)
|
2026-02-08 04:01:48 +00:00
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|