Skip to content

Commit

Permalink
refactor(live-status-gw): reassign log levels
Browse files Browse the repository at this point in the history
demotes many info messages to debug, some even to silly
  • Loading branch information
ianshade committed Mar 11, 2024
1 parent 0f73bed commit 0c25dbb
Show file tree
Hide file tree
Showing 22 changed files with 119 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class AdLibActionsHandler
}

async changed(id: AdLibActionId, changeType: string): Promise<void> {
this._logger.info(`${this._name} ${changeType} ${id}`)
this.logDocumentChange(id, changeType)
if (!this._collectionName) return
const col = this._core.getCollection(this._collectionName)
if (!col) throw new Error(`collection '${this._collectionName}' not found!`)
Expand All @@ -31,7 +31,7 @@ export class AdLibActionsHandler
}

async update(source: string, data: SelectedPartInstances | undefined): Promise<void> {
this._logger.info(`${this._name} received partInstances update from ${source}`)
this.logUpdateReceived('partInstances', source)
const prevRundownId = this._curRundownId
this._curPartInstance = data ? data.current ?? data.next : undefined
this._curRundownId = this._curPartInstance ? this._curPartInstance.rundownId : undefined
Expand Down Expand Up @@ -69,7 +69,7 @@ export class AdLibActionsHandler

// override notify to implement empty array handling
async notify(data: AdLibAction[] | undefined): Promise<void> {
this._logger.info(`${this._name} notifying update with ${data?.length} adLibActions`)
this.logNotifyingUpdate(data?.length)
if (data !== undefined) {
for (const observer of this._observers) {
await observer.update(this._name, data)
Expand Down
6 changes: 3 additions & 3 deletions packages/live-status-gateway/src/collections/adLibsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class AdLibsHandler
}

async changed(id: PieceId, changeType: string): Promise<void> {
this._logger.info(`${this._name} ${changeType} ${id}`)
this.logDocumentChange(id, changeType)
if (!this._collectionName) return
const col = this._core.getCollection(this._collectionName)
if (!col) throw new Error(`collection '${this._collectionName}' not found!`)
Expand All @@ -32,7 +32,7 @@ export class AdLibsHandler
}

async update(source: string, data: SelectedPartInstances | undefined): Promise<void> {
this._logger.info(`${this._name} received adLibs update from ${source}`)
this.logUpdateReceived('partInstances', source)
const prevRundownId = this._currentRundownId
this._currentPartInstance = data ? data.current ?? data.next : undefined
this._currentRundownId = this._currentPartInstance?.rundownId
Expand Down Expand Up @@ -70,7 +70,7 @@ export class AdLibsHandler

// override notify to implement empty array handling
async notify(data: AdLibPiece[] | undefined): Promise<void> {
this._logger.info(`${this._name} notifying update with ${data?.length} adLibs`)
this.logNotifyingUpdate(data?.length)
if (data !== undefined) {
for (const observer of this._observers) {
await observer.update(this._name, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class GlobalAdLibActionsHandler
}

async changed(id: RundownBaselineAdLibActionId, changeType: string): Promise<void> {
this._logger.info(`${this._name} ${changeType} ${id}`)
this.logDocumentChange(id, changeType)
if (!this._collectionName) return
const col = this._core.getCollection(this._collectionName)
if (!col) throw new Error(`collection '${this._collectionName}' not found!`)
Expand All @@ -39,7 +39,7 @@ export class GlobalAdLibActionsHandler
}

async update(source: string, data: SelectedPartInstances | undefined): Promise<void> {
this._logger.info(`${this._name} received partInstances update from ${source}`)
this.logUpdateReceived('partInstances', source)
const prevRundownId = this._currentRundownId
const partInstance = data ? data.current ?? data.next : undefined
this._currentRundownId = partInstance?.rundownId
Expand Down Expand Up @@ -75,7 +75,7 @@ export class GlobalAdLibActionsHandler

// override notify to implement empty array handling
async notify(data: RundownBaselineAdLibAction[] | undefined): Promise<void> {
this._logger.info(`${this._name} notifying update with ${data?.length} globalAdLibActions`)
this.logNotifyingUpdate(data?.length)
if (data !== undefined) {
for (const observer of this._observers) {
await observer.update(this._name, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class GlobalAdLibsHandler
}

async changed(id: PieceId, changeType: string): Promise<void> {
this._logger.info(`${this._name} ${changeType} ${id}`)
this.logDocumentChange(id, changeType)
if (!this._collectionName) return
const collection = this._core.getCollection(this._collectionName)
if (!collection) throw new Error(`collection '${this._collectionName}' not found!`)
Expand All @@ -39,7 +39,7 @@ export class GlobalAdLibsHandler
}

async update(source: string, data: SelectedPartInstances | undefined): Promise<void> {
this._logger.info(`${this._name} received globalAdLibs update from ${source}`)
this.logUpdateReceived('globalAdLibs', source)
const prevRundownId = this._currentRundownId
const partInstance = data ? data.current ?? data.next : undefined
this._currentRundownId = partInstance?.rundownId
Expand Down Expand Up @@ -75,7 +75,7 @@ export class GlobalAdLibsHandler

// override notify to implement empty array handling
async notify(data: RundownBaselineAdLibItem[] | undefined): Promise<void> {
this._logger.info(`${this._name} notifying update with ${data?.length} globalAdLibs`)
this.logNotifyingUpdate(data?.length)
if (data !== undefined) {
for (const observer of this._observers) {
await observer.update(this._name, data)
Expand Down
8 changes: 4 additions & 4 deletions packages/live-status-gateway/src/collections/partHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class PartHandler
}

async changed(id: PartId, changeType: string): Promise<void> {
this._logger.info(`${this._name} ${changeType} ${id}`)
this.logDocumentChange(id, changeType)
if (!this._collectionName) return
const collection = this._core.getCollection(this._collectionName)
if (!collection) throw new Error(`collection '${this._collectionName}' not found!`)
Expand All @@ -46,11 +46,11 @@ export class PartHandler
const partInstances = data as SelectedPartInstances
switch (source) {
case PlaylistHandler.name:
this._logger.info(`${this._name} received playlist update ${rundownPlaylist?._id}`)
this.logUpdateReceived('playlist', source, `rundownPlaylistId ${rundownPlaylist?._id}`)
this._activePlaylist = rundownPlaylist
break
case PartInstancesHandler.name:
this._logger.info(`${this._name} received partInstances update from ${source}`)
this.logUpdateReceived('partInstances', source)
this._currentPartInstance = partInstances.current
break
default:
Expand Down Expand Up @@ -89,7 +89,7 @@ export class PartHandler
await this._partsHandler.setParts(allParts)
}
if (prevCurPartInstance !== this._currentPartInstance) {
this._logger.info(
this._logger.debug(
`${this._name} found updated partInstances with current part ${this._activePlaylist?.currentPartInfo?.partInstanceId}`
)
if (!collection) throw new Error(`collection '${this._collectionName}' not found!`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class PartInstancesHandler
}

async changed(id: PartInstanceId, changeType: string): Promise<void> {
this._logger.info(`${this._name} ${changeType} ${id}`)
this.logDocumentChange(id, changeType)
if (!this._collectionName || this._subscriptionPending) return

this._throttledUpdateAndNotify()
Expand Down Expand Up @@ -101,10 +101,10 @@ export class PartInstancesHandler
const prevRundownIds = this._rundownIds.map((rid) => rid)
const prevActivationId = this._activationId

this._logger.info(
`${this._name} received playlist update ${data?._id}, active ${
data?.activationId ? true : false
} from ${source}`
this.logUpdateReceived(
'playlist',
source,
`rundownPlaylistId ${data?._id}, active ${data?.activationId ? true : false}`
)
this._currentPlaylist = data
if (!this._collectionName) return
Expand Down
6 changes: 2 additions & 4 deletions packages/live-status-gateway/src/collections/partsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ export class PartsHandler
}

async setParts(parts: DBPart[]): Promise<void> {
this._logger.info(`'${this._name}' handler received parts update with ${parts.length} parts`)
this.logUpdateReceived('parts', parts.length)
this._collectionData = parts
await this.throttledNotify(this._collectionData)
}

async notify(data: DBPart[] | undefined): Promise<void> {
this._logger.info(
`${this._name} notifying all observers of an update with ${this._collectionData?.length} parts`
)
this.logNotifyingUpdate(this._collectionData?.length)
if (data !== undefined) {
for (const observer of this._observers) {
await observer.update(this._name, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class PieceInstancesHandler
}

async changed(id: PieceInstanceId, changeType: string): Promise<void> {
this._logger.info(`${this._name} ${changeType} ${id}`)
this.logDocumentChange(id, changeType)
if (!this._collectionName || this._subscriptionPending) return
this._throttledUpdateAndNotify()
}
Expand Down Expand Up @@ -111,9 +111,7 @@ export class PieceInstancesHandler
const prevPartInstanceIds = this._partInstanceIds
const prevActivationId = this._activationId

this._logger.info(
`${this._name} received playlist update ${data?._id}, active ${!!data?.activationId} from ${source}`
)
this.logUpdateReceived('playlist', source, `rundownPlaylistId ${data?._id}, active ${!!data?.activationId}`)
this._currentPlaylist = data
if (!this._collectionName) return

Expand Down
12 changes: 5 additions & 7 deletions packages/live-status-gateway/src/collections/playlistHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,25 @@ import { CorelibPubSub } from '@sofie-automation/corelib/dist/pubsub'
import { RundownPlaylistId } from '@sofie-automation/corelib/dist/dataModel/Ids'

export class PlaylistsHandler
extends CollectionBase<DBRundownPlaylist[], undefined, undefined>
extends CollectionBase<DBRundownPlaylist[], undefined, CollectionName.RundownPlaylists>
implements Collection<DBRundownPlaylist[]>
{
public observerName: string

constructor(logger: Logger, coreHandler: CoreHandler) {
super(PlaylistsHandler.name, undefined, undefined, logger, coreHandler)
super(PlaylistsHandler.name, CollectionName.RundownPlaylists, undefined, logger, coreHandler)
this.observerName = this._name
}

async setPlaylists(playlists: DBRundownPlaylist[]): Promise<void> {
this._logger.info(`'${this._name}' handler received playlists update with ${playlists.length} playlists`)
this.logUpdateReceived('playlists', playlists.length)
this._collectionData = playlists
await this.notify(this._collectionData)
}

// override notify to implement empty array handling
async notify(data: DBRundownPlaylist[] | undefined): Promise<void> {
this._logger.info(
`${this._name} notifying all observers of an update with ${this._collectionData?.length} playlists`
)
this.logNotifyingUpdate(this._collectionData?.length)
if (data !== undefined) {
for (const observer of this._observers) {
await observer.update(this._name, data)
Expand Down Expand Up @@ -78,7 +76,7 @@ export class PlaylistHandler
}

async changed(id: RundownPlaylistId, changeType: string): Promise<void> {
this._logger.info(`${this._name} ${changeType} ${id}`)
this.logDocumentChange(id, changeType)
if (!this._collectionName) return
const collection = this._core.getCollection(this._collectionName)
if (!collection) throw new Error(`collection '${this._collectionName}' not found!`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CoreHandler } from '../coreHandler'
import { CollectionBase, Collection, CollectionObserver } from '../wsHandler'
import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
import { DBRundown } from '@sofie-automation/corelib/dist/dataModel/Rundown'
import { unprotectString } from '@sofie-automation/shared-lib/dist/lib/protectedString'
import { PartInstancesHandler, SelectedPartInstances } from './partInstancesHandler'
import { RundownId, RundownPlaylistId } from '@sofie-automation/corelib/dist/dataModel/Ids'
import { CollectionName } from '@sofie-automation/corelib/dist/dataModel/Collections'
Expand All @@ -24,7 +25,7 @@ export class RundownHandler
}

async changed(id: RundownId, changeType: string): Promise<void> {
this._logger.info(`${this._name} ${changeType} ${id}`)
this.logDocumentChange(id, changeType)
if (id !== this._currentRundownId)
throw new Error(`${this._name} received change with unexpected id ${id} !== ${this._currentRundownId}`)
if (!this._collectionName) return
Expand All @@ -42,11 +43,11 @@ export class RundownHandler
const partInstances = data as SelectedPartInstances
switch (source) {
case PlaylistHandler.name:
this._logger.info(`${this._name} received playlist update ${rundownPlaylist?._id}`)
this.logUpdateReceived('playlist', source, unprotectString(rundownPlaylist?._id))
this._currentPlaylistId = rundownPlaylist?._id
break
case PartInstancesHandler.name:
this._logger.info(`${this._name} received partInstances update from ${source}`)
this.logUpdateReceived('partInstances', source)
this._currentRundownId = partInstances.current?.rundownId ?? partInstances.next?.rundownId
break
default:
Expand Down
11 changes: 5 additions & 6 deletions packages/live-status-gateway/src/collections/rundownsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,28 @@ import { Logger } from 'winston'
import { CoreHandler } from '../coreHandler'
import { CollectionBase, Collection } from '../wsHandler'
import { DBRundown } from '@sofie-automation/corelib/dist/dataModel/Rundown'
import { CollectionName } from '@sofie-automation/corelib/dist/dataModel/Collections'

export class RundownsHandler
extends CollectionBase<DBRundown[], undefined, undefined>
extends CollectionBase<DBRundown[], undefined, CollectionName.Rundowns>
implements Collection<DBRundown[]>
{
public observerName: string

constructor(logger: Logger, coreHandler: CoreHandler) {
super(RundownsHandler.name, undefined, undefined, logger, coreHandler)
super(RundownsHandler.name, CollectionName.Rundowns, undefined, logger, coreHandler)
this.observerName = this._name
}

async setRundowns(rundowns: DBRundown[]): Promise<void> {
this._logger.info(`'${this._name}' handler received rundowns update with ${rundowns.length} rundowns`)
this.logUpdateReceived('rundowns', rundowns.length)
this._collectionData = rundowns
await this.notify(this._collectionData)
}

// override notify to implement empty array handling
async notify(data: DBRundown[] | undefined): Promise<void> {
this._logger.info(
`${this._name} notifying all observers of an update with ${this._collectionData?.length} rundowns`
)
this.logNotifyingUpdate(this._collectionData?.length)
if (data !== undefined) {
for (const observer of this._observers) {
await observer.update(this._name, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class SegmentHandler
}

async changed(id: SegmentId, changeType: string): Promise<void> {
this._logger.info(`${this._name} ${changeType} ${id}`)
this.logDocumentChange(id, changeType)
if (!this._collectionName) return
const collection = this._core.getCollection(this._collectionName)
if (!collection) throw new Error(`collection '${this._collectionName}' not found!`)
Expand All @@ -43,13 +43,13 @@ export class SegmentHandler

switch (source) {
case PartInstancesHandler.name: {
this._logger.info(`${this._name} received update from ${source}`)
this.logUpdateReceived('partInstances', source)
const partInstanceMap = data as SelectedPartInstances
this._currentSegmentId = data ? partInstanceMap.current?.segmentId : undefined
break
}
case PlaylistHandler.name: {
this._logger.info(`${this._name} received update from ${source}`)
this.logUpdateReceived('playlist', source)
this._rundownIds = (data as DBRundownPlaylist | undefined)?.rundownIdsInOrder ?? []
break
}
Expand Down
11 changes: 5 additions & 6 deletions packages/live-status-gateway/src/collections/segmentsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,32 @@ import { CoreHandler } from '../coreHandler'
import { CollectionBase, Collection } from '../wsHandler'
import { DBSegment } from '@sofie-automation/corelib/dist/dataModel/Segment'
import * as _ from 'underscore'
import { CollectionName } from '@sofie-automation/corelib/dist/dataModel/Collections'

const THROTTLE_PERIOD_MS = 200

export class SegmentsHandler
extends CollectionBase<DBSegment[], undefined, undefined>
extends CollectionBase<DBSegment[], undefined, CollectionName.Segments>
implements Collection<DBSegment[]>
{
public observerName: string
private throttledNotify: (data: DBSegment[]) => Promise<void>

constructor(logger: Logger, coreHandler: CoreHandler) {
super(SegmentsHandler.name, undefined, undefined, logger, coreHandler)
super(SegmentsHandler.name, CollectionName.Segments, undefined, logger, coreHandler)
this.observerName = this._name
this.throttledNotify = _.throttle(this.notify.bind(this), THROTTLE_PERIOD_MS, { leading: true, trailing: true })
}

async setSegments(segments: DBSegment[]): Promise<void> {
this._logger.info(`'${this._name}' handler received segments update with ${segments.length} segments`)
this.logUpdateReceived('segments', segments.length)
this._collectionData = segments
await this.throttledNotify(this._collectionData)
}

// override notify to implement empty array handling
async notify(data: DBSegment[] | undefined): Promise<void> {
this._logger.info(
`${this._name} notifying all observers of an update with ${this._collectionData?.length} segments`
)
this.logNotifyingUpdate(this._collectionData?.length)
if (data !== undefined) {
for (const observer of this._observers) {
await observer.update(this._name, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ShowStyleBaseHandler
}

async changed(id: ShowStyleBaseId, changeType: string): Promise<void> {
this._logger.info(`${this._name} ${changeType} ${id}`)
this.logDocumentChange(id, changeType)
if (!this._collectionName) return
if (this._showStyleBaseId) {
this.updateCollectionData()
Expand All @@ -44,9 +44,7 @@ export class ShowStyleBaseHandler
}

async update(source: string, data: DBRundown | undefined): Promise<void> {
this._logger.info(
`${this._name} received rundown update ${data?._id}, showStyleBaseId ${data?.showStyleBaseId} from ${source}`
)
this.logUpdateReceived('rundown', source, `rundownId ${data?._id}, showStyleBaseId ${data?.showStyleBaseId}`)
const prevShowStyleBaseId = this._showStyleBaseId
this._showStyleBaseId = data?.showStyleBaseId

Expand Down
Loading

0 comments on commit 0c25dbb

Please sign in to comment.