Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add max concurrent runs config for triggers #1255

Merged
merged 1 commit into from
Nov 25, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ const EnabledCompositeTriggerRowView = ({
? (compositeTrigger.trigger as ICompositeTrigger).triggers[0].programId.application
: compositeTrigger.name;

const concurrencyConstraint = compositeTrigger.constraints.find(
(constraint) => constraint.type === 'CONCURRENCY'
);
const maxConcurrentRuns = concurrencyConstraint ? concurrencyConstraint.maxConcurrency : '_';

const handleConfirmModalOpen = (e) => {
e.stopPropagation();
setShowDeleteModal(true);
Expand Down Expand Up @@ -139,6 +144,10 @@ const EnabledCompositeTriggerRowView = ({
isLoading={loading}
closeable={true}
/>
<PipelineName>
{T.translate(`${TRIGGER_PREFIX}.pipelineTriggerConcurrencyHeader`, { maxConcurrentRuns })}
</PipelineName>
<br />
{(compositeTrigger.trigger as ICompositeTrigger).triggers.map((trigger) => {
return (
<StyledEnabledInlineTriggerRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ const EnabledTriggerRowView = ({
workflowName,
}: IEnabledTriggerRowViewProps) => {
const currentTrigger = schedule.trigger as IProgramStatusTrigger;
const concurrencyConstraint = schedule.constraints.find(
(constraint) => constraint.type === 'CONCURRENCY'
);
const maxConcurrentRuns = concurrencyConstraint ? concurrencyConstraint.maxConcurrency : '_';
const [showDeleteModal, setShowDeleteModal] = useState(false);
const [selectedNamespace, setSelectedNamesapce] = useState(null);
const [payloadModalOpen, setPayloadModalOpen] = useState(false);
Expand Down Expand Up @@ -138,6 +142,10 @@ const EnabledTriggerRowView = ({

return (
<div>
<StyledNameSpace>
{T.translate(`${TRIGGER_PREFIX}.pipelineTriggerConcurrencyHeader`, { maxConcurrentRuns })}
</StyledNameSpace>
<br />
<PipelineDescription>
<strong>{T.translate(`${TRIGGER_PREFIX}.description`)}: </strong>
{info ? <span>{info && info.description}</span> : renderLoading()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import React, { useEffect, useReducer } from 'react';
import styled from 'styled-components';
import {
changeMaxConcurrentRuns,
changeNamespace,
changeTriggersType,
enableGroupTrigger,
Expand Down Expand Up @@ -54,6 +55,7 @@ import {
} from 'components/PipelineTriggers/reducer';
import PayloadConfigModal from 'components/PipelineTriggers/PayloadConfigModal';
import PipelineCompositeTriggerRow from './PipelineCompositeTriggerRow';
import { DEFAULT_TRIGGER_MAX_CONCURRENT_RUNS } from '../store/PipelineTriggersStore';

const TRIGGER_PREFIX = 'features.PipelineTriggers';
const PREFIX = `${TRIGGER_PREFIX}.SetTriggers`;
Expand Down Expand Up @@ -146,6 +148,7 @@ interface IPipelineListCompositeTabViewProps {
configureError: string;
onPayloadToggle: (isOpen: boolean) => void;
setTab: (tab: number) => void;
maxConcurrentRuns?: number;
}

const PipelineListCompositeTabView = ({
Expand All @@ -160,6 +163,7 @@ const PipelineListCompositeTabView = ({
toggleExpandPipeline,
configureError,
setTab,
maxConcurrentRuns = DEFAULT_TRIGGER_MAX_CONCURRENT_RUNS,
}: IPipelineListCompositeTabViewProps) => {
const [state, dispatch] = useReducer(triggerNameReducer, initialAvailablePipelineListState);
const emptyTriggerErrorMsg =
Expand Down Expand Up @@ -220,6 +224,10 @@ const PipelineListCompositeTabView = ({
changeTriggersType(e.target.value);
};

const handleChangeMaxConcurrentRuns = (e) => {
changeMaxConcurrentRuns(e.target.value);
};

const addGroupTriggerClick = () => {
enableGroupTrigger(state.triggerName, setTab, state.computeProfile);
};
Expand Down Expand Up @@ -277,6 +285,24 @@ const PipelineListCompositeTabView = ({
</select>
</SelectorDropdown>
</div>
<div>
<TriggerConfigHeader>{T.translate(`${PREFIX}.maxConcurrentRuns`)}</TriggerConfigHeader>
<SelectorDropdown data-testid="composite-trigger-max-concurrent-runs">
<select
className="form-control"
value={maxConcurrentRuns}
onChange={handleChangeMaxConcurrentRuns}
>
{Array(10)
.fill(0)
.map((_, i) => (
<option value={i + 1} key={i + 1}>
{i + 1}
</option>
))}
</select>
</SelectorDropdown>
</div>
<div>
<TriggerConfigHeader>{T.translate(`${PREFIX}.triggerName`)}</TriggerConfigHeader>
<TriggerNameTextField
Expand Down Expand Up @@ -397,6 +423,7 @@ const mapStateToProps = (state) => {
pipelineName: state.triggers.pipelineName,
expandedPipeline: state.triggers.expandedPipeline,
configureError: state.triggers.configureError,
maxConcurrentRuns: state.triggers.maxConcurrentRuns,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ export function changeTriggersType(selectedTriggersType: string) {
});
}

export function changeMaxConcurrentRuns(maxConcurrentRuns: number) {
PipelineTriggersStore.dispatch({
type: PipelineTriggersActions.setMaxConcurrentRuns,
payload: {
maxConcurrentRuns,
},
});
}

/**
* Method to remove the selected trigger from the composite AND or OR trigger group.
*/
Expand Down Expand Up @@ -174,7 +183,7 @@ export function enableGroupTrigger(
},
constraints: [
{
maxConcurrency: 3,
maxConcurrency: pipelineTriggers.maxConcurrentRuns,
type: 'CONCURRENCY',
waitUntilMet: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const PipelineTriggersActions = {
setPayloadModalState: 'TRIGGERS_SET_PAYLOAD_MODAL_STATE',
setTriggerType: 'TRIGGERS_SET_TYPE',
reset: 'TRIGGERS_RESET',
setMaxConcurrentRuns: 'TRIGGERS_SET_MAX_CONCURRENT_RUNS',
};

export default PipelineTriggersActions;
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
} from 'components/PipelineTriggers/store/ScheduleTypes';
import PipelineTriggersTypes from 'components/PipelineTriggers/store/PipelineTriggersTypes';

export const DEFAULT_TRIGGER_MAX_CONCURRENT_RUNS = 3;

interface IPayLoad {
pipelineName?: string;
workflowName?: string;
Expand All @@ -41,6 +43,7 @@ interface IPayLoad {
isOpen?: boolean;
expandedSchedule?: string;
pipelineInfo?: IPipelineInfo;
maxConcurrentRuns?: number;
}

interface IAction {
Expand Down Expand Up @@ -71,6 +74,7 @@ const defaultInitialState = {
configureError: null,
pipelineCompositeTriggersEnabled: false,
lifecycleManagementEditEnabled: false,
maxConcurrentRuns: DEFAULT_TRIGGER_MAX_CONCURRENT_RUNS,
};

const defaultInitialEnabledTriggersState = {
Expand Down Expand Up @@ -159,6 +163,12 @@ const triggers = (state = defaultInitialState, action = defaultAction) => {
configureError: action.payload.error,
};
break;
case PipelineTriggersActions.setMaxConcurrentRuns:
stateCopy = {
...state,
maxConcurrentRuns: action.payload.maxConcurrentRuns,
};
break;
case PipelineTriggersActions.reset:
return defaultInitialState;
default:
Expand Down
2 changes: 2 additions & 0 deletions app/cdap/text/text-en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2819,6 +2819,7 @@ features:
groupTriggers: Composite Triggers
pipelineTriggerType: "Trigger Type: {type}"
pipelineTriggerTypeHeader: "Type"
pipelineTriggerConcurrencyHeader: "Max concurrent runs: {maxConcurrentRuns}"
ScheduleRuntimeArgs:
configure_enable_btn: Configure and Enable Trigger
configure_select_btn: Select
Expand Down Expand Up @@ -2860,6 +2861,7 @@ features:
SetTriggers:
addNewTrigger: Enable the trigger
configComputeProfie: Compute Profile
maxConcurrentRuns: Max concurrent runs
compositeTriggersTitle: "Add a new trigger for \"{pipelineName}\""
buttonLabel: Enable Trigger
pipelineCount: "{count} pipelines available"
Expand Down
Loading