-
Notifications
You must be signed in to change notification settings - Fork 3
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
SOF-1670 Expose Endpoint To Reload Rundown #88
Changes from 1 commit
09d1f53
d0a17c9
94f95d9
0c4095b
7e1d1da
eb17bc3
0b715e6
052dda7
07159a0
6d7ed67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,15 +74,19 @@ | |
"dependencies": { | ||
"@sofie-automation/blueprints-integration": "npm:@tv2media/[email protected]", | ||
"@sofie-automation/server-core-integration": "npm:@tv2media/[email protected]", | ||
"@tv2media/logger": "^1.2.4", | ||
"@sofie-automation/shared-lib": "npm:@tv2media/[email protected]", | ||
"@tv2media/logger": "^1.2.4", | ||
"@types/dotenv": "^6.1.1", | ||
"@types/koa": "^2.13.10", | ||
"@types/koa-router": "^7.4.6", | ||
"@types/xml2js": "^0.4.4", | ||
"async-mutex": "^0.3.1", | ||
"cross-env": "^7.0.3", | ||
"dotenv": "^8.0.0", | ||
"inews": "npm:@tv2media/[email protected]", | ||
"jobs-queue": "git+https://github.com/sparkpunkd/node-jobs-queue.git#master", | ||
"koa": "^2.14.2", | ||
"koa-router": "^12.0.1", | ||
"lodash.clonedeep": "^4.5.0", | ||
"tslib": "^2.0.0", | ||
"underscore": "^1.9.1", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ import { Observer } from '@sofie-automation/server-core-integration' | |
import { ensureLogLevel, setLogLevel } from './logger' | ||
import { ILogger as Logger } from '@tv2media/logger' | ||
import { unprotectString } from '@sofie-automation/shared-lib/dist/lib/protectedString' | ||
import * as Koa from 'koa' | ||
import * as KoaRouter from 'koa-router' | ||
|
||
export interface Config { | ||
process: ProcessConfig | ||
|
@@ -31,6 +33,9 @@ export class Connector { | |
private _process: Process | ||
private _settings?: INewsDeviceSettings | ||
private _debug: boolean | ||
private koaApp: Koa | ||
private koaRouter: KoaRouter | ||
|
||
|
||
constructor(logger: Logger, config: Config, debug: boolean) { | ||
this._logger = logger.tag(this.constructor.name) | ||
|
@@ -40,6 +45,8 @@ export class Connector { | |
this.coreHandler = new CoreHandler(this._logger, this._config.device) | ||
this.iNewsFTPHandler = new InewsFTPHandler(this._logger, this.coreHandler) | ||
this.coreHandler.iNewsHandler = this.iNewsFTPHandler | ||
this.koaApp = new Koa() | ||
this.koaRouter = new KoaRouter() | ||
} | ||
|
||
async init(): Promise<void> { | ||
|
@@ -52,6 +59,7 @@ export class Connector { | |
this._logger.info('Core is initialized') | ||
this.setupObserver() | ||
this._logger.info('Initialization of FTP-monitor done') | ||
this.setupReloadDataKoaEndpoint() | ||
} catch (err) { | ||
this._logger.data(err).error(`Error during initialization:`) | ||
|
||
|
@@ -134,4 +142,20 @@ export class Connector { | |
|
||
addedChanged(unprotectString(this.coreHandler.core.deviceId)) | ||
} | ||
|
||
private setupReloadDataKoaEndpoint(): void { | ||
this.koaRouter.get('/reloadData/:rundownName', async (ctx, next): Promise<void> => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps another method than GET should be used, since we are not reading the data out, but triggering a computation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did think about this, what is more correct in this scenario? POST and PUT, for instance, would signify that the we actually submit something rather than trigger a computation, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now it has been changed to a POST. |
||
const RUNDOWN_EXTERNAL_ID_SUFFIX = '_1' | ||
if (!this.iNewsFTPHandler.iNewsWatcher) { | ||
return | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case where we can't reload the data, wouldn't the caller be interested in knowing that the rundown has not been reloaded? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added more handling towards this purpose! |
||
this.iNewsFTPHandler.iNewsWatcher?.ResyncRundown(ctx.params.rundownName + RUNDOWN_EXTERNAL_ID_SUFFIX) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A mistake on my part, i must have forgot to remove it after i made the guard for that very purpose :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have changed it! |
||
|
||
await next() | ||
}) | ||
|
||
this.koaApp.use(this.koaRouter.routes()).use(this.koaRouter.allowedMethods()) | ||
|
||
this.koaApp.listen(3007, () => {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice if the port was also in a constant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved into a constant |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctx
stands for context?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
next: Koa.next
and that would be nice to add but i decided not to since the type for context:ctx: Koa.ParameterizedContext<any, KoaRouter.IRouterParamContext<any, {}>, any>
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use a custom type that encapsulates the data that you need from the koa context.