Skip to content

Commit

Permalink
refactor: removes possibility for arguments being optional as the are…
Browse files Browse the repository at this point in the history
… always supplied. fix: sets status in core when failing to download iNews rundown.
  • Loading branch information
andr9528 committed Nov 15, 2023
1 parent a9c49b5 commit a8426d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions src/classes/RundownManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { ReducedRundown, ReducedSegment, UnrankedSegment } from './RundownWatche
import { literal, parseModifiedDateFromInewsStoryWithFallbackToNow, ReflectPromise } from '../helpers'
import { VERSION } from '../version'
import { SegmentId } from '../helpers/id'
import { ILogger as Logger } from '@tv2media/logger'
import { ILogger } from '@tv2media/logger'
import { CoreHandler } from "../coreHandler";
import { StatusCode } from "@sofie-automation/shared-lib/dist/lib/status";

function isFile(f: INewsDirItem): f is INewsFile {
return f.filetype === 'file'
Expand All @@ -15,11 +17,9 @@ export class RundownManager {
private _listStories!: (queueName: string) => Promise<Array<INewsDirItem>>
private _getStory!: (queueName: string, story: string) => Promise<INewsStory>

constructor(private _logger?: Logger, private inewsConnection?: INewsClient) {
if (this.inewsConnection) {
this._listStories = promisify(this.inewsConnection.list).bind(this.inewsConnection)
this._getStory = promisify(this.inewsConnection.story).bind(this.inewsConnection)
}
constructor(private _logger: ILogger, private inewsConnection: INewsClient, private coreHandler: CoreHandler) {
this._listStories = promisify(this.inewsConnection.list).bind(this.inewsConnection)
this._getStory = promisify(this.inewsConnection.story).bind(this.inewsConnection)
}

/**
Expand Down Expand Up @@ -57,7 +57,8 @@ export class RundownManager {
}
})
} catch (error) {
this._logger?.data(error).error('Error downloading iNews rundown:')
this._logger.data(error).error('Error downloading iNews rundown:')
await this.coreHandler.setStatus(StatusCode.FATAL, ['Error downloading iNews rundown', (error as Error).message])
}
return rundown
}
Expand Down Expand Up @@ -110,15 +111,15 @@ export class RundownManager {
locator: (storyFile as INewsFile).locator,
}
} catch (err) {
this._logger?.error(`Error downloading iNews story: ${err}`)
this._logger.error(`Error downloading iNews story: ${err}`)
return undefined
}

this._logger?.debug('Downloaded : ' + queueName + ' : ' + (storyFile as INewsFile).identifier)
this._logger.debug('Downloaded : ' + queueName + ' : ' + (storyFile as INewsFile).identifier)
/* Add fileId and update modifyDate to ftp reference in storyFile */
story.fields.modifyDate = `${storyFile.modified ? storyFile.modified.getTime() / 1000 : 0}`

this._logger?.debug(`Queue: ${queueName} Story: ${isFile(storyFile) ? storyFile.storyName : storyFile.file}`)
this._logger.debug(`Queue: ${queueName} Story: ${isFile(storyFile) ? storyFile.storyName : storyFile.file}`)

return story
}
Expand Down
2 changes: 1 addition & 1 deletion src/classes/RundownWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class RundownWatcher extends EventEmitter {
super()
this._logger = this.logger.tag(this.constructor.name)

this.rundownManager = new RundownManager(this._logger, this.iNewsConnection)
this.rundownManager = new RundownManager(this._logger, this.iNewsConnection, this.coreHandler)

if (!delayStart) {
this.startWatcher()
Expand Down

0 comments on commit a8426d8

Please sign in to comment.