Fix operation check
This commit is contained in:
@@ -92,7 +92,7 @@ func (h *TranscribeHandler) CreateTranscribeJob(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Создаем запись в таблице transcribe_jobs
|
||||
jobId := uuid.New().String()
|
||||
jobId := uuid.NewString()
|
||||
now := time.Now()
|
||||
job := &entity.TranscribeJob{
|
||||
Id: jobId,
|
||||
@@ -293,7 +293,8 @@ func (h *TranscribeHandler) RunRecognitionJob(c *gin.Context) {
|
||||
|
||||
// Обновляем задачу с ID операции распознавания
|
||||
job.RecognitionOpID = &operationID
|
||||
job.MoveToState(entity.StateTranscribe)
|
||||
delayTime := time.Now().Add(time.Minute)
|
||||
job.MoveToStateAndDelay(entity.StateTranscribe, &delayTime)
|
||||
|
||||
err = h.jobRepo.Save(job)
|
||||
if err != nil {
|
||||
@@ -306,7 +307,7 @@ func (h *TranscribeHandler) RunRecognitionJob(c *gin.Context) {
|
||||
|
||||
func (h *TranscribeHandler) RunRecognitionCheckJob(c *gin.Context) {
|
||||
acquisitionId := uuid.NewString()
|
||||
rottingTime := time.Now().Add(-1 * time.Hour)
|
||||
rottingTime := time.Now().Add(-24 * time.Hour)
|
||||
|
||||
job, err := h.jobRepo.FindAndAcquire(entity.StateTranscribe, acquisitionId, rottingTime)
|
||||
if err != nil {
|
||||
@@ -325,6 +326,7 @@ func (h *TranscribeHandler) RunRecognitionCheckJob(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to initialize SpeechKit service: " + err.Error()})
|
||||
return
|
||||
}
|
||||
defer speechKitService.Close()
|
||||
|
||||
// Проверяем статус операции
|
||||
operation, err := speechKitService.CheckOperationStatus(*job.RecognitionOpID)
|
||||
@@ -334,8 +336,24 @@ func (h *TranscribeHandler) RunRecognitionCheckJob(c *gin.Context) {
|
||||
}
|
||||
|
||||
if !operation.Done {
|
||||
// Операция еще не завершена, переводим в состояние ожидания
|
||||
err = h.jobRepo.Save(job)
|
||||
// Операция еще не завершена, оставляем в статусе обработки
|
||||
delayTime := time.Now().Add(10 * time.Second)
|
||||
job.MoveToStateAndDelay(entity.StateTranscribe, &delayTime)
|
||||
err := h.jobRepo.Save(job)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to update job: " + err.Error()})
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusOK)
|
||||
return
|
||||
}
|
||||
|
||||
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)
|
||||
err := h.jobRepo.Save(job)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to update job: " + err.Error()})
|
||||
return
|
||||
|
Reference in New Issue
Block a user