generated from SergioNR/express-js-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Update to latest version #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
189983c
Replace logInfo with console.log for logging
SergioNR 48a311d
UPDATE prisma schema to allow for one-to-many relationship between tr…
SergioNR 1f0fc25
REFACTOR pendingTranscriptionJob to a fire and forget function
SergioNR 1485ccb
ADD no-return-await exception to eslint config
SergioNR 9236c7f
FIX typo in S3 client
SergioNR 483078d
UPDATE processing transcriptions to 5 minutes
SergioNR 732d7b3
REFACTOR transcription job processing process
SergioNR 3a681ab
REMOVE unused parameter in transcription model
SergioNR 52d4fbc
Merge pull request #32 from UXcaptain/improve-transcription-job-logic
SergioNR aecf7a9
HOTFIX: update prisma.schema to accomodate for recently pushed changes
SergioNR 4641324
PIN prisma to v6
SergioNR 9668654
HOTFIX redaction in loggers
SergioNR cabe036
REMOVE unneeded await in pendingTranscriptionScheduler
SergioNR a03d854
Merge branch 'latest' into next
SergioNR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| { | ||
| "prisma.fileWatcher": true | ||
| "prisma.fileWatcher": true, | ||
| "prisma.pinToPrisma6": true | ||
| } |
5 changes: 5 additions & 0 deletions
5
...85631_remove_analysis_entry_id_uniqueness_to_allow_for_transcription_reruns/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| -- DropIndex | ||
| DROP INDEX "TranscriptionJob_analysis_entry_id_key"; | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "TranscriptionJob_status_idx" ON "TranscriptionJob"("status"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,88 @@ | ||
| import { logError, logInfo } from '../config/loggerFunctions.js'; | ||
| import { transcribeRecording } from '../integrations/whisper-asr-webservice/transcribe.js'; | ||
| import { | ||
| getPendingTranscriptionJobsFromDb, | ||
| getFirstTranscriptionJobFromDbByStatus, | ||
| storeNormalizedTranscriptionInDb, | ||
| updateStatusSingleTranscriptionJobInDb, | ||
| } from '../models/transcriptionModel.js'; | ||
| import { cleanUpTranscriptSegments } from '../utils/transcription/transcriptionNormalizer.js'; | ||
|
|
||
| export const processPendingTranscriptionJobs = async () => { | ||
| const pendingTranscriptionJobs = await getPendingTranscriptionJobsFromDb(); | ||
| // check if there is an ongoing transcription job | ||
|
|
||
| if (pendingTranscriptionJobs.length === 0) { | ||
| console.log('No pending transcription jobs found'); | ||
| return; | ||
| let inProgressTranscriptionJob; | ||
|
|
||
| try { | ||
| inProgressTranscriptionJob = await getFirstTranscriptionJobFromDbByStatus('IN_PROGRESS'); | ||
| } catch (error) { | ||
| return logError('error fetching first transcription job from DB', error); | ||
| } | ||
| if (inProgressTranscriptionJob) { | ||
| return console.log(`Transcription job id: ${inProgressTranscriptionJob.id} is in progress Skipping new jobs.`); // * Set as console log for registering but not cluttering logs | ||
| } | ||
|
|
||
| let pendingTranscriptionJob; | ||
|
|
||
| try { | ||
| pendingTranscriptionJob = await getFirstTranscriptionJobFromDbByStatus('PENDING'); | ||
| } catch (error) { | ||
| return logError('Error fetching first pending transcription job from DB', error); | ||
| } | ||
|
|
||
| if (!pendingTranscriptionJob) { | ||
| return console.log('No pending transcription jobs found.'); // * Set as console log for registering but not cluttering logs | ||
| } | ||
|
|
||
| for (const transcriptionJob of pendingTranscriptionJobs) { | ||
| logInfo(`Processing transcription job for analysis entry ID: ${transcriptionJob.analysis_entry_id}`); | ||
| const { | ||
| id: transcriptionJobId, | ||
| analysis_entry_id: analysisEntryId, | ||
| } = pendingTranscriptionJob; | ||
|
|
||
| const { analysis_entry_id: analysisEntryId } = transcriptionJob; | ||
| logInfo(`Processing transcription job ${transcriptionJobId} for analysis entry ID: ${analysisEntryId}`); | ||
|
|
||
| try { | ||
| // Mark job as IN_PROGRESS before making async call to prevent re-queuing | ||
| await updateStatusSingleTranscriptionJobInDb(analysisEntryId, 'IN_PROGRESS'); | ||
| logInfo(`Marked transcription job ${analysisEntryId} as IN_PROGRESS`); | ||
| try { // Mark job as IN_PROGRESS before making async call to prevent re-queuing | ||
| await updateStatusSingleTranscriptionJobInDb(transcriptionJobId, 'IN_PROGRESS'); | ||
| logInfo(`Marked transcription job ${transcriptionJobId} for analysis entry ID ${analysisEntryId} as IN_PROGRESS`); | ||
| } catch (error) { | ||
| return logError(`error updating status for transcription job ${transcriptionJobId} to IN_PROGRESS`, error); | ||
| } | ||
|
|
||
| const transcriptionJobResult = await transcribeRecording(transcriptionJob); | ||
| let transcriptionJobResult; | ||
|
|
||
| const { segments, text: fullText } = transcriptionJobResult; | ||
| try { | ||
| transcriptionJobResult = await transcribeRecording(pendingTranscriptionJob); | ||
| } catch (error) { | ||
| logError(`error transcribing recording for transcription job ${transcriptionJobId}`, error); | ||
| return await updateStatusSingleTranscriptionJobInDb(transcriptionJobId, 'PENDING'); | ||
| } | ||
| const { | ||
| segments, | ||
| text: fullText, | ||
| } = transcriptionJobResult; | ||
|
|
||
| const cleanedUpSegments = await cleanUpTranscriptSegments(segments); | ||
| let cleanedUpSegments; | ||
|
|
||
| await storeNormalizedTranscriptionInDb(analysisEntryId, fullText, cleanedUpSegments); | ||
| try { | ||
| cleanedUpSegments = await cleanUpTranscriptSegments(segments); | ||
| } catch (error) { | ||
| logError(`error cleaning up transcript segments for transcription job ${transcriptionJobId}`, error); | ||
| return await updateStatusSingleTranscriptionJobInDb(transcriptionJobId, 'PENDING'); | ||
| } | ||
|
|
||
| await updateStatusSingleTranscriptionJobInDb(analysisEntryId, 'COMPLETED'); | ||
| try { | ||
| await storeNormalizedTranscriptionInDb(analysisEntryId, fullText, cleanedUpSegments); | ||
| } catch (error) { | ||
| logError(`error inserting normalized transcription from transcription job ${transcriptionJobId} in analysis entry ${analysisEntryId}`, error); | ||
| return await updateStatusSingleTranscriptionJobInDb(transcriptionJobId, 'PENDING'); | ||
| } | ||
|
|
||
| logInfo(`Transcription job ${analysisEntryId} completed successfully`); | ||
| } catch (error) { | ||
| // Mark job back as PENDING to allow retry | ||
| await updateStatusSingleTranscriptionJobInDb(analysisEntryId, 'PENDING'); | ||
| logError(`Error processing transcription job, ${analysisEntryId}`, error); | ||
| } | ||
| try { | ||
| await updateStatusSingleTranscriptionJobInDb(transcriptionJobId, 'COMPLETED'); | ||
| logInfo(`Marked transcription job ${transcriptionJobId} for analysis entry ID ${analysisEntryId} as COMPLETED`); | ||
| } catch (error) { | ||
| logError(`error updating status for transcription job ${transcriptionJobId} to COMPLETED`, error); | ||
| return await updateStatusSingleTranscriptionJobInDb(transcriptionJobId, 'PENDING'); | ||
| } | ||
|
|
||
| return logInfo(`Transcription job ${transcriptionJobId} for analysis entry ID ${analysisEntryId} completed successfully`); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,6 @@ | ||
| import { CronJob } from 'cron'; | ||
| import { processPendingTranscriptionJobs } from '../controllers/transcriptionController.js'; | ||
| import { logError } from '../config/loggerFunctions.js'; | ||
|
|
||
| export const getPendingTranscriptionJobScheduler = new CronJob('*/15 * * * *', async () => { | ||
| try { | ||
| await processPendingTranscriptionJobs(); | ||
| } catch (error) { | ||
| logError('Error processing transcription request', error); | ||
| } | ||
| export const getPendingTranscriptionJobScheduler = new CronJob('*/5 * * * *', () => { | ||
| processPendingTranscriptionJobs(); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.