-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better orion language detection (#337)
* New model to track orion language processing * New function to detect language * New custom migration * Add cursor tracker and video orion language to offchain export * Running `custom-migration` command * Add manger to trigger video language updates * Adjust orion video language manager to support video update * Revert "Running `custom-migration` command" This reverts commit 71c4997. * Second run of `create-migrations` command * CR fixes * move 'orion_offchain_cursor' table to admin schema * bump package version and add change log * fix: bug in case detected language is undefined --------- Co-authored-by: Zeeshan Akram <97m.zeeshan@gmail.com>
- Loading branch information
1 parent
d65135f
commit 6167139
Showing
15 changed files
with
223 additions
and
113 deletions.
There are no files selected for viewing
This file contains 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 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 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,11 @@ | ||
module.exports = class Data1720623003671 { | ||
name = 'Data1720623003671' | ||
|
||
async up(db) { | ||
await db.query(`CREATE TABLE "admin"."orion_offchain_cursor" ("cursor_name" character varying NOT NULL, "value" bigint NOT NULL, CONSTRAINT "PK_7083797352af5a21224b6c8ccbc" PRIMARY KEY ("cursor_name"))`) | ||
} | ||
|
||
async down(db) { | ||
await db.query(`DROP TABLE "admin"."orion_offchain_cursor"`) | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
db/migrations/1709641962433-Views.js → db/migrations/1720623003800-Views.js
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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,20 @@ | ||
import { Column, Entity, PrimaryColumn } from 'typeorm' | ||
|
||
@Entity({ schema: 'admin' }) | ||
export class OrionOffchainCursor { | ||
constructor(props?: Partial<OrionOffchainCursor>) { | ||
Object.assign(this, props) | ||
} | ||
|
||
/** | ||
* Name of the offchain cursor | ||
*/ | ||
@PrimaryColumn() | ||
cursorName!: string | ||
|
||
/** | ||
* Value of the cursor | ||
*/ | ||
@Column('int8', { nullable: false }) | ||
value!: number | ||
} |
This file contains 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,2 +1,3 @@ | ||
export * from './generated' | ||
export { NextEntityId } from './NextEntityId' | ||
export { OrionOffchainCursor } from './OrionOffchainCursor' |
This file contains 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,64 @@ | ||
import { EntityManager } from 'typeorm' | ||
import { | ||
detectVideoLanguageWithProvider, | ||
updateVideoLanguages, | ||
VIDEO_ORION_LANGUAGE_CURSOR_NAME, | ||
} from './customMigrations/setOrionLanguageProvider' | ||
import { globalEm } from './globalEm' | ||
|
||
export class OrionVideoLanguageManager { | ||
private videoToDetect: Set<string> = new Set() | ||
|
||
async init(intervalMs: number): Promise<void> { | ||
if (!VIDEO_ORION_LANGUAGE_CURSOR_NAME) { | ||
return | ||
} | ||
|
||
this.updateLoop(intervalMs) | ||
.then(() => { | ||
/* Do nothing */ | ||
}) | ||
.catch((err) => { | ||
console.error(err) | ||
process.exit(-1) | ||
}) | ||
} | ||
|
||
scheduleVideoForDetection(id: string | null | undefined) { | ||
if (id) { | ||
this.videoToDetect.add(id) | ||
} | ||
} | ||
|
||
async updateScheduledVideoLanguage(em: EntityManager) { | ||
if (!this.videoToDetect.size) { | ||
return | ||
} | ||
|
||
const videos = await em.query(` | ||
SELECT id, title, description | ||
FROM admin.video | ||
WHERE id in (${[...this.videoToDetect.values()].map((id) => `'${id}'`).join(',')}) | ||
`) | ||
|
||
await updateVideoLanguages(em, videos) | ||
this.videoToDetect.clear() | ||
} | ||
|
||
async updateOrionVideoLanguage() { | ||
return detectVideoLanguageWithProvider() | ||
} | ||
|
||
private async updateLoop(intervalMs: number): Promise<void> { | ||
const em = await globalEm | ||
while (true) { | ||
await this.updateScheduledVideoLanguage(em).catch((e) => { | ||
console.log(`Updating scheduled videos Orion language with provider failed`, e) | ||
}) | ||
await this.updateOrionVideoLanguage().catch((e) => { | ||
console.log(`Updating Orion language with provider failed`, e) | ||
}) | ||
await new Promise((resolve) => setTimeout(resolve, intervalMs)) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.