From a7a06808db6443508b696543cc3ec1383b6558ec Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Tue, 4 Jun 2024 07:13:23 +0100 Subject: [PATCH] Add tags plugins --- .../tools/tagsRequeue/1.0.0/index.ts | 146 ++++++++++++++++++ .../tools/tagsWorkerType/1.0.0/index.ts | 139 +++++++++++++++++ 2 files changed, 285 insertions(+) create mode 100644 FlowPluginsTs/CommunityFlowPlugins/tools/tagsRequeue/1.0.0/index.ts create mode 100644 FlowPluginsTs/CommunityFlowPlugins/tools/tagsWorkerType/1.0.0/index.ts diff --git a/FlowPluginsTs/CommunityFlowPlugins/tools/tagsRequeue/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/tools/tagsRequeue/1.0.0/index.ts new file mode 100644 index 0000000..27339fc --- /dev/null +++ b/FlowPluginsTs/CommunityFlowPlugins/tools/tagsRequeue/1.0.0/index.ts @@ -0,0 +1,146 @@ +import { + IpluginDetails, + IpluginInputArgs, + IpluginOutputArgs, +} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces'; + +/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ +const details = (): IpluginDetails => ({ + name: 'Tags: Requeue', + description: ` +Place the file back in the staging queue with specific tags. + +Only Nodes/Workers which match the tags will be able to process the file. + +The tags must have one of the following: 'requireCPU', 'requireGPU', or 'requireCPUorGPU'. + +The above tells the server what type of worker is required to process the file. + +Subsequent tags must not use the reserved word 'require' in them. + +You can set the 'Node Tags' in the Node options panel. + +The the item tags in the staging section must be a subset of the required tags for a worker to process the file. +`, + style: { + borderColor: 'yellow', + }, + tags: '', + isStartPlugin: false, + pType: '', + requiresVersion: '2.20.01', + sidebarPosition: -1, + icon: 'faRedo', + inputs: [ + { + label: 'Use Basic Queue Tags', + name: 'useBasicQueueTags', + type: 'boolean', + defaultValue: 'true', + inputUI: { + type: 'switch', + }, + tooltip: 'Use basic queue tags or custom tags.', + }, + { + label: 'Basic Queue Tags', + name: 'basicQueueTags', + type: 'string', + defaultValue: 'requireCPU', + inputUI: { + type: 'dropdown', + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'useBasicQueueTags', + value: 'true', + condition: '===', + }, + ], + }, + ], + }, + options: [ + 'requireCPU', + 'requireGPU', + 'requireGPU:nvenc', + 'requireGPU:qsv', + 'requireGPU:vaapi', + 'requireGPU:videotoolbox', + 'requireGPU:amf', + 'requireCPUorGPU', + ], + }, + tooltip: 'Specify tags to requeue file with.', + }, + { + label: 'Custom Queue Tags', + name: 'customQueueTags', + type: 'string', + defaultValue: 'requireCPUorGPU,tag1', + inputUI: { + type: 'textarea', + style: { + height: '100px', + }, + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'useBasicQueueTags', + value: 'true', + condition: '!==', + }, + ], + }, + ], + }, + }, + tooltip: ` +requireGPU:nvenc,tag1,tag2 +requireCPUorGPU,tag1,tag2 +requireCPU,tag1,tag2 +requireGPU,tag1,tag2,tag3 +requireGPU,tag1 +requireGPU,{{{args.userVariables.global.test}}} +requireCPUorGPU,tag1,tag2 + `, + }, + ], + outputs: [ + { + number: 1, + tooltip: 'Continue to next plugin', + }, + ], +}); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { + const lib = require('../../../../../methods/lib')(); + // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign + args.inputs = lib.loadDefaultValues(args.inputs, details); + + const basicQueueTags = String(args.inputs.basicQueueTags); + const customQueueTags = String(args.inputs.customQueueTags); + + // eslint-disable-next-line no-param-reassign + args.variables.queueTags = args.inputs.useBasicQueueTags ? basicQueueTags : customQueueTags; + + return { + outputFileObj: args.inputFileObj, + outputNumber: 1, + variables: args.variables, + }; +}; +export { + details, + plugin, +}; diff --git a/FlowPluginsTs/CommunityFlowPlugins/tools/tagsWorkerType/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/tools/tagsWorkerType/1.0.0/index.ts new file mode 100644 index 0000000..7431802 --- /dev/null +++ b/FlowPluginsTs/CommunityFlowPlugins/tools/tagsWorkerType/1.0.0/index.ts @@ -0,0 +1,139 @@ +import { + IpluginDetails, + IpluginInputArgs, + IpluginOutputArgs, +} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces'; + +/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ +const details = (): IpluginDetails => ({ + name: 'Tags: Worker Type', + description: ` +Requeues the item into the staging section if the current worker +does not match the required worker type and tags. + +You can set the 'Node Tags' in the Node options panel. + +The current tags must be a subset of the required tags. + `, + style: { + borderColor: 'yellow', + }, + tags: '', + isStartPlugin: false, + pType: '', + requiresVersion: '2.20.01', + sidebarPosition: -1, + icon: 'faFilter', + inputs: [ + { + label: 'Required Transcode Worker Type', + name: 'requiredWorkerType', + type: 'string', + defaultValue: 'CPUorGPU', + inputUI: { + type: 'dropdown', + options: [ + 'CPUorGPU', + 'CPU', + 'GPU', + 'GPU:nvenc', + 'GPU:qsv', + 'GPU:vaapi', + 'GPU:videotoolbox', + 'GPU:amf', + ], + }, + tooltip: 'Specify worker type', + }, + { + label: 'Required Node Tags', + name: 'requiredNodeTags', + type: 'string', + defaultValue: '', + inputUI: { + type: 'textarea', + style: { + height: '100px', + }, + }, + tooltip: ` +tag1,tag2 + `, + }, + ], + outputs: [ + { + number: 1, + tooltip: 'Continue to next plugin', + }, + ], +}); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { + const lib = require('../../../../../methods/lib')(); + // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign + args.inputs = lib.loadDefaultValues(args.inputs, details); + + const requiredWorkerType = String(args.inputs.requiredWorkerType); + const requiredNodeTags = String(args.inputs.requiredNodeTags); + + let requiredTags = []; + let currentTags = []; + + requiredTags.push(`require${requiredWorkerType}`); + if (requiredNodeTags) { + requiredTags = requiredTags.concat(requiredNodeTags.split(',').map((tag) => tag.trim())); + } + + const currentWorkerType = args.workerType; + + if (requiredWorkerType === 'CPUorGPU') { + currentTags.push('requireCPUorGPU'); + } else if (currentWorkerType === 'transcodecpu') { + currentTags.push('requireCPU'); + } else if (currentWorkerType === 'transcodegpu') { + if (args.nodeHardwareType && args.nodeHardwareType !== '-') { + currentTags.push(`requireGPU:${args.nodeHardwareType}`); + } else { + currentTags.push('requireGPU'); + } + } + + if (args.nodeTags) { + currentTags = currentTags.concat(args.nodeTags.split(',').map((tag) => tag.trim())); + } + + args.jobLog(`Required Tags: ${requiredTags.join(',')}`); + args.jobLog(`Current Tags: ${currentTags.join(',')}`); + + let isSubset = true; + + for (let i = 0; i < currentTags.length; i += 1) { + if (!requiredTags.includes(currentTags[i])) { + isSubset = false; + break; + } + } + + if (isSubset) { + // eslint-disable-next-line no-param-reassign + args.variables.queueTags = ''; + args.jobLog('Worker type and tags are subset of required tags'); + } else { + // eslint-disable-next-line no-param-reassign + args.variables.queueTags = requiredTags.join(','); + args.jobLog('Worker type and tags are not subset of required tags,' + + ` requeueing with tags ${args.variables.queueTags}`); + } + + return { + outputFileObj: args.inputFileObj, + outputNumber: 1, + variables: args.variables, + }; +}; +export { + details, + plugin, +};