The key item here is that comms.phone and comms.email are meant to represent a real global namespace, but comms.contact is meant to represent an organization-specific namespace. This means the mapping, comms.contact_phone and comms.contact_email can't key off the global namespace. Otherwise the contact namespace would implicitly be global.
65 lines
2.2 KiB
Go
65 lines
2.2 KiB
Go
package background
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/Gleipnir-Technology/bob"
|
|
"github.com/aarondl/opt/omit"
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/db"
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/db/enums"
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/public/model"
|
|
"source.gleipnir.technology/Gleipnir/nidus-sync/db/models"
|
|
query "source.gleipnir.technology/Gleipnir/nidus-sync/db/query/public"
|
|
//"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func NewAudioTranscode(ctx context.Context, txn bob.Executor, audio_id int32) error {
|
|
return newJob(ctx, txn, enums.JobtypeAudioTranscode, audio_id)
|
|
}
|
|
func NewComplianceMailer(ctx context.Context, txn db.Ex, compliance_report_request_id int32) error {
|
|
return newJob2(ctx, txn, model.Jobtype_ComplianceMailerSend, compliance_report_request_id)
|
|
}
|
|
func NewCSVCommit(ctx context.Context, txn bob.Executor, csv_id int32) error {
|
|
return newJob(ctx, txn, enums.JobtypeCSVCommit, csv_id)
|
|
}
|
|
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)
|
|
}
|
|
func NewTextRespond(ctx context.Context, txn db.Ex, text_id int32) error {
|
|
return newJob2(ctx, txn, model.Jobtype_TextRespond, text_id)
|
|
}
|
|
func NewTextSend(ctx context.Context, txn db.Ex, job_id int32) error {
|
|
return newJob2(ctx, txn, model.Jobtype_TextSend, job_id)
|
|
}
|
|
func newJob(ctx context.Context, txn bob.Executor, t enums.Jobtype, id int32) error {
|
|
_, err := models.Jobs.Insert(&models.JobSetter{
|
|
Created: omit.From(time.Now()),
|
|
// ID
|
|
Type: omit.From(t),
|
|
RowID: omit.From(id),
|
|
}).One(ctx, txn)
|
|
if err != nil {
|
|
return fmt.Errorf("insert job: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
func newJob2(ctx context.Context, txn db.Ex, t model.Jobtype, id int32) error {
|
|
job := model.Job{
|
|
Created: time.Now(),
|
|
Type: t,
|
|
RowID: id,
|
|
}
|
|
_, err := query.JobInsert(ctx, txn, job)
|
|
if err != nil {
|
|
return fmt.Errorf("insert job: %w", err)
|
|
}
|
|
return nil
|
|
}
|