Files
2025-08-17 15:26:59 +03:00

65 lines
1.8 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package entity
import (
"time"
)
type TranscribeJob struct {
Id string
State string
Source string
FileID *string
IsError bool
ErrorText *string
AcquisitionID *string
AcquireTime *time.Time
DelayTime *time.Time
RecognitionOpID *string // ID операции распознавания в Yandex Cloud
TranscriptionText *string // Результат распознавания
TgChatId *int64 // Telegram: в какой чат отправить результат распознавания
TgReplyMessageId *int // Telegram: с каким сообщением связать результат распознавания
CreatedAt time.Time
UpdatedAt time.Time
}
const (
StateCreated = "created"
StateConverted = "converted"
StateTranscribe = "transcribe"
StateDone = "done"
StateFailed = "failed"
)
const (
SourceUnknown = "unknown"
SourceApi = "api"
SourceTelegram = "telegram"
)
// Переводит задачу в новое состояние, при этом очищает все
// служебные поля предыдущего состояния, как-то время задержки, информацию о воркере и тд
func (j *TranscribeJob) MoveToState(state string) {
j.State = state
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()
}
func (j *TranscribeJob) Done(transcriptionText string) {
j.MoveToState(StateDone)
j.TranscriptionText = &transcriptionText
}
func (j *TranscribeJob) Fail(errText string) {
j.MoveToState(StateFailed)
j.IsError = true
j.ErrorText = &errText
}