@@ -4,67 +4,74 @@ import { MediaWorkFlows, PeripheralDevices } from '../collections'
44import { executePeripheralDeviceFunction } from './peripheralDevice/executeFunction'
55import { MediaWorkFlowId , OrganizationId , PeripheralDeviceId } from '@sofie-automation/corelib/dist/dataModel/Ids'
66
7- export namespace MediaManagerAPI {
8- export async function restartAllWorkflows ( organizationId : OrganizationId | null ) : Promise < void > {
9- const devices : Array < Pick < PeripheralDevice , '_id' > > = await PeripheralDevices . findFetchAsync (
10- organizationId ? { organizationId : organizationId } : { } ,
11- {
12- fields : {
13- _id : 1 ,
14- } ,
15- }
16- )
17- const workflows : Array < Pick < MediaWorkFlow , 'deviceId' > > = await MediaWorkFlows . findFetchAsync (
18- {
19- deviceId : { $in : devices . map ( ( d ) => d . _id ) } ,
7+ export async function restartAllWorkflows ( organizationId : OrganizationId | null ) : Promise < void > {
8+ const devices : Array < Pick < PeripheralDevice , '_id' > > = await PeripheralDevices . findFetchAsync (
9+ organizationId ? { organizationId : organizationId } : { } ,
10+ {
11+ fields : {
12+ _id : 1 ,
2013 } ,
21- {
22- fields : {
23- deviceId : 1 ,
24- } ,
25- }
26- )
14+ }
15+ )
16+ const workflows : Array < Pick < MediaWorkFlow , 'deviceId' > > = await MediaWorkFlows . findFetchAsync (
17+ {
18+ deviceId : { $in : devices . map ( ( d ) => d . _id ) } ,
19+ } ,
20+ {
21+ fields : {
22+ deviceId : 1 ,
23+ } ,
24+ }
25+ )
2726
28- const deviceIds = Array . from ( new Set ( workflows . map ( ( w ) => w . deviceId ) ) )
27+ const deviceIds = Array . from ( new Set ( workflows . map ( ( w ) => w . deviceId ) ) )
2928
30- await Promise . all (
31- deviceIds . map ( async ( deviceId ) => executePeripheralDeviceFunction ( deviceId , 'restartAllWorkflows' ) )
32- )
33- }
34- export async function abortAllWorkflows ( organizationId : OrganizationId | null ) : Promise < void > {
35- const devices : Array < Pick < PeripheralDevice , '_id' > > = await PeripheralDevices . findFetchAsync (
36- organizationId ? { organizationId : organizationId } : { } ,
37- {
38- fields : {
39- _id : 1 ,
40- } ,
41- }
42- )
43- const workflows : Array < Pick < MediaWorkFlow , 'deviceId' > > = await MediaWorkFlows . findFetchAsync (
44- {
45- deviceId : { $in : devices . map ( ( d ) => d . _id ) } ,
29+ await Promise . all (
30+ deviceIds . map ( async ( deviceId ) => executePeripheralDeviceFunction ( deviceId , 'restartAllWorkflows' ) )
31+ )
32+ }
33+ export async function abortAllWorkflows ( organizationId : OrganizationId | null ) : Promise < void > {
34+ const devices : Array < Pick < PeripheralDevice , '_id' > > = await PeripheralDevices . findFetchAsync (
35+ organizationId ? { organizationId : organizationId } : { } ,
36+ {
37+ fields : {
38+ _id : 1 ,
39+ } ,
40+ }
41+ )
42+ const workflows : Array < Pick < MediaWorkFlow , 'deviceId' > > = await MediaWorkFlows . findFetchAsync (
43+ {
44+ deviceId : { $in : devices . map ( ( d ) => d . _id ) } ,
45+ } ,
46+ {
47+ fields : {
48+ deviceId : 1 ,
4649 } ,
47- {
48- fields : {
49- deviceId : 1 ,
50- } ,
51- }
52- )
50+ }
51+ )
52+
53+ const deviceIds = Array . from ( new Set ( workflows . map ( ( w ) => w . deviceId ) ) )
54+
55+ await Promise . all ( deviceIds . map ( async ( deviceId ) => executePeripheralDeviceFunction ( deviceId , 'abortAllWorkflows' ) ) )
56+ }
5357
54- const deviceIds = Array . from ( new Set ( workflows . map ( ( w ) => w . deviceId ) ) )
58+ export async function restartWorkflow ( deviceId : PeripheralDeviceId , workflowId : MediaWorkFlowId ) : Promise < void > {
59+ await ensureWorkflowExists ( workflowId )
5560
56- await Promise . all (
57- deviceIds . map ( async ( deviceId ) => executePeripheralDeviceFunction ( deviceId , 'abortAllWorkflows' ) )
58- )
59- }
61+ await executePeripheralDeviceFunction ( deviceId , 'restartWorkflow' , workflowId )
62+ }
63+ export async function abortWorkflow ( deviceId : PeripheralDeviceId , workflowId : MediaWorkFlowId ) : Promise < void > {
64+ await ensureWorkflowExists ( workflowId )
65+
66+ await executePeripheralDeviceFunction ( deviceId , 'abortWorkflow' , workflowId )
67+ }
68+ export async function prioritizeWorkflow ( deviceId : PeripheralDeviceId , workflowId : MediaWorkFlowId ) : Promise < void > {
69+ await ensureWorkflowExists ( workflowId )
70+
71+ await executePeripheralDeviceFunction ( deviceId , 'prioritizeWorkflow' , workflowId )
72+ }
6073
61- export async function restartWorkflow ( deviceId : PeripheralDeviceId , workflowId : MediaWorkFlowId ) : Promise < void > {
62- await executePeripheralDeviceFunction ( deviceId , 'restartWorkflow' , workflowId )
63- }
64- export async function abortWorkflow ( deviceId : PeripheralDeviceId , workflowId : MediaWorkFlowId ) : Promise < void > {
65- await executePeripheralDeviceFunction ( deviceId , 'abortWorkflow' , workflowId )
66- }
67- export async function prioritizeWorkflow ( deviceId : PeripheralDeviceId , workflowId : MediaWorkFlowId ) : Promise < void > {
68- await executePeripheralDeviceFunction ( deviceId , 'prioritizeWorkflow' , workflowId )
69- }
74+ async function ensureWorkflowExists ( workflowId : MediaWorkFlowId ) : Promise < void > {
75+ const doc = await MediaWorkFlows . findOneAsync ( workflowId , { projection : { _id : 1 } } )
76+ if ( ! doc ) throw new Error ( `Workflow "${ workflowId } " not found` )
7077}
0 commit comments