Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/package-manager/packages/generic/src/coreHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export class CoreHandler {
restartPackageContainer(containerId: PackageContainerId): void {
return this._packageManagerHandler?.restartPackageContainer(containerId)
}
troubleshoot(): any {
async troubleshoot(): Promise<any> {
return this._packageManagerHandler?.getDataSnapshot()
}
async getExpetationManagerStatus(): Promise<any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function getExpectations(
// A blueprint-like plug-in architecture might be a future idea

/** If set, we should first copy media to a temporary storage and use that for side-effects */
const useTemporaryStorage = packageContainers[TEMPORARY_STORAGE_ID]
const useTemporaryStorage = packageContainers[TEMPORARY_STORAGE_ID] as PackageContainer | undefined

// Sort, so that we handle the high-priority first:
expectedPackages.sort((a, b) => {
Expand Down
4 changes: 2 additions & 2 deletions apps/package-manager/packages/generic/src/packageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ export class PackageManagerHandler {
// This method can be called from core
this.expectationManager.restartPackageContainer(containerId)
}
public getDataSnapshot(): any {
public async getDataSnapshot(): Promise<any> {
return {
...this.dataSnapshot,

Expand All @@ -426,7 +426,7 @@ export class PackageManagerHandler {
reportedPackageStatuses: mapToObject(this.callbacksHandler.reportedPackageStatuses),
reportedPackageContainerStatuses: mapToObject(this.callbacksHandler.reportedPackageContainerStatuses),
},
expectationManager: this.expectationManager.getTroubleshootData(),
expectationManager: await this.expectationManager.getTroubleshootData(),
}
}
public async getExpetationManagerStatus(): Promise<any> {
Expand Down
2 changes: 2 additions & 0 deletions shared/packages/api/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ReturnTypeDisposePackageContainerMonitors,
ReturnTypeDoYouSupportExpectation,
ReturnTypeDoYouSupportPackageContainer,
ReturnTypeGetConfiguration,
ReturnTypeIsExpectationFulfilled,
ReturnTypeIsExpectationReadyToStartWorkingOn,
ReturnTypeRemoveExpectation,
Expand Down Expand Up @@ -101,6 +102,7 @@ export namespace ExpectationManagerWorkerAgent {
/** Methods on WorkerAgent, called by ExpectedManager */
export interface WorkerAgent extends MethodsInterfaceBase {
id: ExpectationManagerId
getConfiguration: () => Promise<ReturnTypeGetConfiguration>
doYouSupportExpectation: (exp: Expectation.Any) => Promise<ReturnTypeDoYouSupportExpectation>
getCostForExpectation: (exp: Expectation.Any) => Promise<ExpectationCost>
isExpectationReadyToStartWorkingOn: (
Expand Down
3 changes: 3 additions & 0 deletions shared/packages/api/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
* This file contains API definitions for the Worker methods
*/

import { WorkerConfig } from './config'
import { MonitorId } from './ids'
import { Reason } from './methods'

export type ReturnTypeGetConfiguration = WorkerConfig

export type ReturnTypeDoYouSupportExpectation =
| {
support: true
Expand Down
24 changes: 20 additions & 4 deletions shared/packages/expectationManager/src/expectationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
WorkerAgentId,
mapToObject,
URLMap,
stringifyError,
} from '@sofie-package-manager/api'
import { InternalManager } from './internalManager/internalManager'
import { ExpectationTrackerConstants } from './lib/constants'
Expand All @@ -36,7 +37,7 @@ export class ExpectationManager {
serverAccessBaseUrls: URLMap | undefined,
workForceConnectionOptions: ClientConnectionOptions,
callbacks: ExpectationManagerCallbacks,
options?: ExpectationManagerOptions
private readonly options?: ExpectationManagerOptions
) {
this.internalManager = new InternalManager(
logger,
Expand All @@ -46,7 +47,7 @@ export class ExpectationManager {
serverAccessBaseUrls,
workForceConnectionOptions,
callbacks,
options
this.options
)
}
terminate(): void {
Expand Down Expand Up @@ -117,7 +118,7 @@ export class ExpectationManager {

this.internalManager.tracker.triggerEvaluationNow()
}
public getTroubleshootData(): any {
public async getTroubleshootData(): Promise<any> {
const trackedExpectations = this.internalManager.tracker.getSortedTrackedExpectations().map((trackedExp) => {
return {
...trackedExp,
Expand All @@ -126,10 +127,25 @@ export class ExpectationManager {
queriedWorkers: mapToObject(trackedExp.queriedWorkers),
}
})

return {
trackedExpectations,
workers: this.internalManager.workerAgents.list(),
workers: await Promise.all(
this.internalManager.workerAgents.list().map(async (worker) => {
let config = undefined
try {
config = await worker.workerAgent.api.getConfiguration()
} catch (err) {
config = `Error getting configuration: ${stringifyError(err)}`
}
return {
...worker,
config,
}
})
),
waitingExpectations: this.internalManager.tracker.scaler.getWaitingExpectationIds(),
config: this.options,
}
}
async getStatusReport(): Promise<any> {
Expand Down
5 changes: 5 additions & 0 deletions shared/packages/expectationManager/src/workerAgentApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ReturnTypeRemoveExpectation,
AdapterServerOptions,
PackageContainerExpectation,
ReturnTypeGetConfiguration,
ReturnTypeDoYouSupportPackageContainer,
ReturnTypeRunPackageContainerCronJob,
ReturnTypeSetupPackageContainerMonitors,
Expand All @@ -34,6 +35,10 @@ export class WorkerAgentAPI
super(methods, options)
}

async getConfiguration(): Promise<ReturnTypeGetConfiguration> {
// Note: This call is ultimately received in shared/packages/worker/src/workerAgent.ts
return this._sendMessage('getConfiguration')
}
async doYouSupportExpectation(exp: Expectation.Any): Promise<ReturnTypeDoYouSupportExpectation> {
// Note: This call is ultimately received in shared/packages/worker/src/workerAgent.ts
return this._sendMessage('doYouSupportExpectation', exp)
Expand Down
9 changes: 6 additions & 3 deletions shared/packages/worker/src/workerAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ export class WorkerAgent {
this.expectationManagers.set(managerId, expectationManager)

const methods = literal<Omit<ExpectationManagerWorkerAgent.WorkerAgent, 'id'>>({
getConfiguration: async () => this.config,
doYouSupportExpectation: async (exp: Expectation.Any): Promise<ReturnTypeDoYouSupportExpectation> => {
return this.doesWorkerSupportExpectation(exp)
},
Expand Down Expand Up @@ -847,9 +848,11 @@ export class WorkerAgent {
if (!result.success) knownReason = result.knownReason
} else if ('ready' in result) {
if (!result.ready) knownReason = result.knownReason
} else if ('cost' in result) {
// do nothing
} else if ('wipId' in result) {
} else if (
'cost' in result || // ExpectationCost
'wipId' in result || // WorkInProgressInfo
'process' in result // ReturnTypeGetConfiguration
) {
// do nothing
} else {
assertNever(result)
Expand Down
Loading