Add job helpers
This commit is contained in:
@@ -40,3 +40,14 @@ func (j *TranscribeJob) MoveToStateAndDelay(state string, delay *time.Time) {
|
||||
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
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ func NewTranscribeService(jobRepo repo.TranscriptJobRepository, fileRepo repo.Fi
|
||||
|
||||
func (s *TranscribeService) CreateTranscribeJob(file io.Reader, fileName string) (*entity.TranscribeJob, error) {
|
||||
// Генерируем UUID для файла
|
||||
fileId := uuid.New().String()
|
||||
fileId := uuid.NewString()
|
||||
|
||||
// Определяем расширение файла
|
||||
ext := filepath.Ext(fileName)
|
||||
@@ -247,10 +247,8 @@ func (s *TranscribeService) FindAndRunTranscribeCheckJob() error {
|
||||
}
|
||||
|
||||
if opErr := operation.GetError(); opErr != nil {
|
||||
job.IsError = true
|
||||
errorText := fmt.Sprintf("Operation failed: code %d, message: %s", opErr.Code, opErr.Message)
|
||||
job.ErrorText = &errorText
|
||||
job.MoveToState(entity.StateFailed)
|
||||
job.Fail(errorText)
|
||||
err := s.jobRepo.Save(job)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -265,8 +263,7 @@ func (s *TranscribeService) FindAndRunTranscribeCheckJob() error {
|
||||
}
|
||||
|
||||
// Обновляем задачу с результатом
|
||||
job.TranscriptionText = &transcriptionText
|
||||
job.MoveToState(entity.StateDone)
|
||||
job.Done(transcriptionText)
|
||||
|
||||
err = s.jobRepo.Save(job)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user