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