Fix job fields naiming
This commit is contained in:
@@ -93,12 +93,14 @@ func (h *TranscribeHandler) CreateTranscribeJob(c *gin.Context) {
|
||||
|
||||
// Создаем запись в таблице transcribe_jobs
|
||||
jobId := uuid.New().String()
|
||||
now := time.Now()
|
||||
job := &entity.TranscribeJob{
|
||||
Id: jobId,
|
||||
State: entity.StateCreated,
|
||||
FileID: &fileId,
|
||||
IsError: false,
|
||||
CreatedAt: time.Now(),
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
if err := h.jobRepo.Create(job); err != nil {
|
||||
|
@@ -10,11 +10,13 @@ type TranscribeJob struct {
|
||||
FileID *string
|
||||
IsError bool
|
||||
ErrorText *string
|
||||
Worker *string
|
||||
AcquiredAt *time.Time
|
||||
CreatedAt time.Time
|
||||
AcquisitionID *string
|
||||
AcquireTime *time.Time
|
||||
DelayTime *time.Time
|
||||
RecognitionOpID *string // ID операции распознавания в Yandex Cloud
|
||||
TranscriptionText *string // Результат распознавания
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -28,6 +30,14 @@ const (
|
||||
|
||||
func (j *TranscribeJob) MoveToState(state string) {
|
||||
j.State = state
|
||||
j.Worker = nil
|
||||
j.AcquiredAt = nil
|
||||
j.DelayTime = nil
|
||||
j.AcquisitionID = nil
|
||||
j.AcquireTime = nil
|
||||
j.UpdatedAt = time.Now()
|
||||
}
|
||||
|
||||
func (j *TranscribeJob) MoveToStateAndDelay(state string, delay *time.Time) {
|
||||
j.MoveToState(state)
|
||||
j.DelayTime = delay
|
||||
j.UpdatedAt = time.Now()
|
||||
}
|
||||
|
@@ -26,11 +26,13 @@ func (repo *TranscriptJobRepository) Create(job *entity.TranscribeJob) error {
|
||||
"file_id": job.FileID,
|
||||
"is_error": job.IsError,
|
||||
"error_text": job.ErrorText,
|
||||
"worker": job.Worker,
|
||||
"acquired_at": job.AcquiredAt,
|
||||
"created_at": job.CreatedAt,
|
||||
"acquisition_id": job.AcquisitionID,
|
||||
"acquire_time": job.AcquireTime,
|
||||
"delay_time": job.DelayTime,
|
||||
"recognition_op_id": job.RecognitionOpID,
|
||||
"transcription_text": job.TranscriptionText,
|
||||
"created_at": job.CreatedAt,
|
||||
"updated_at": job.UpdatedAt,
|
||||
}
|
||||
query := repo.gq.Insert("transcribe_jobs").Rows(record)
|
||||
sql, args, err := query.ToSQL()
|
||||
@@ -52,10 +54,12 @@ func (repo *TranscriptJobRepository) Save(job *entity.TranscribeJob) error {
|
||||
"file_id": job.FileID,
|
||||
"is_error": job.IsError,
|
||||
"error_text": job.ErrorText,
|
||||
"worker": job.Worker,
|
||||
"acquired_at": job.AcquiredAt,
|
||||
"acquisition_id": job.AcquisitionID,
|
||||
"acquire_time": job.AcquireTime,
|
||||
"delay_time": job.DelayTime,
|
||||
"recognition_op_id": job.RecognitionOpID,
|
||||
"transcription_text": job.TranscriptionText,
|
||||
"updated_at": job.UpdatedAt,
|
||||
}
|
||||
query := repo.gq.Update("transcribe_jobs").Set(record).Where(goqu.C("id").Eq(job.Id))
|
||||
sql, args, err := query.ToSQL()
|
||||
@@ -78,11 +82,13 @@ func (repo *TranscriptJobRepository) GetByID(id string) (*entity.TranscribeJob,
|
||||
"file_id",
|
||||
"is_error",
|
||||
"error_text",
|
||||
"worker",
|
||||
"acquired_at",
|
||||
"created_at",
|
||||
"acquisition_id",
|
||||
"acquire_time",
|
||||
"delay_time",
|
||||
"recognition_op_id",
|
||||
"transcription_text",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
).Where(goqu.C("id").Eq(id))
|
||||
sql, args, err := query.ToSQL()
|
||||
if err != nil {
|
||||
@@ -96,11 +102,13 @@ func (repo *TranscriptJobRepository) GetByID(id string) (*entity.TranscribeJob,
|
||||
&job.FileID,
|
||||
&job.IsError,
|
||||
&job.ErrorText,
|
||||
&job.Worker,
|
||||
&job.AcquiredAt,
|
||||
&job.CreatedAt,
|
||||
&job.AcquisitionID,
|
||||
&job.AcquireTime,
|
||||
&job.DelayTime,
|
||||
&job.RecognitionOpID,
|
||||
&job.TranscriptionText,
|
||||
&job.CreatedAt,
|
||||
&job.UpdatedAt,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get transcribe job: %w", err)
|
||||
@@ -113,8 +121,8 @@ func (repo *TranscriptJobRepository) FindAndAcquire(state, acquisitionId string,
|
||||
updateQuery := repo.gq.Update("transcribe_jobs").
|
||||
Set(
|
||||
goqu.Record{
|
||||
"worker": acquisitionId,
|
||||
"acquired_at": time.Now(),
|
||||
"acquisition_id": acquisitionId,
|
||||
"acquire_time": time.Now(),
|
||||
},
|
||||
).
|
||||
Where(
|
||||
@@ -125,8 +133,12 @@ func (repo *TranscriptJobRepository) FindAndAcquire(state, acquisitionId string,
|
||||
goqu.C("state").Eq(state),
|
||||
goqu.C("is_error").Eq(0),
|
||||
goqu.Or(
|
||||
goqu.C("worker").IsNull(),
|
||||
goqu.C("acquired_at").Lt(rottingTime),
|
||||
goqu.C("delay_time").IsNull(),
|
||||
goqu.C("delay_time").Lt(time.Now()),
|
||||
),
|
||||
goqu.Or(
|
||||
goqu.C("acquisition_id").IsNull(),
|
||||
goqu.C("acquire_time").Lt(rottingTime),
|
||||
),
|
||||
),
|
||||
).
|
||||
@@ -159,12 +171,14 @@ func (repo *TranscriptJobRepository) FindAndAcquire(state, acquisitionId string,
|
||||
"file_id",
|
||||
"is_error",
|
||||
"error_text",
|
||||
"worker",
|
||||
"acquired_at",
|
||||
"created_at",
|
||||
"acquisition_id",
|
||||
"acquire_time",
|
||||
"delay_time",
|
||||
"recognition_op_id",
|
||||
"transcription_text",
|
||||
).Where(goqu.C("worker").Eq(acquisitionId))
|
||||
"created_at",
|
||||
"updated_at",
|
||||
).Where(goqu.C("acquisition_id").Eq(acquisitionId))
|
||||
|
||||
sql, args, err = selectQuery.ToSQL()
|
||||
if err != nil {
|
||||
@@ -178,11 +192,13 @@ func (repo *TranscriptJobRepository) FindAndAcquire(state, acquisitionId string,
|
||||
&job.FileID,
|
||||
&job.IsError,
|
||||
&job.ErrorText,
|
||||
&job.Worker,
|
||||
&job.AcquiredAt,
|
||||
&job.CreatedAt,
|
||||
&job.AcquisitionID,
|
||||
&job.AcquireTime,
|
||||
&job.DelayTime,
|
||||
&job.RecognitionOpID,
|
||||
&job.TranscriptionText,
|
||||
&job.CreatedAt,
|
||||
&job.UpdatedAt,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get transcribe job: %w", err)
|
||||
|
@@ -2,17 +2,17 @@
|
||||
CREATE TABLE transcribe_jobs (
|
||||
id TEXT PRIMARY KEY,
|
||||
state TEXT NOT NULL,
|
||||
file_id TEXT,
|
||||
delay_time DATETIME,
|
||||
|
||||
is_error BOOLEAN NOT NULL,
|
||||
error_text TEXT,
|
||||
file_id TEXT,
|
||||
recognition_op_id TEXT,
|
||||
transcription_text TEXT,
|
||||
|
||||
acquisition_id TEXT,
|
||||
acquire_time DATETIME,
|
||||
delay_time DATETIME,
|
||||
|
||||
recognition_op_id TEXT,
|
||||
transcription_text TEXT,
|
||||
is_error BOOLEAN NOT NULL,
|
||||
error_text TEXT,
|
||||
|
||||
created_at DATETIME NOT NULL,
|
||||
updated_at DATETIME NOT NULL,
|
||||
|
Reference in New Issue
Block a user