Skip to content

Commit

Permalink
add launch all functionality for manual tick sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
dliu27 committed Oct 30, 2024
1 parent 174d590 commit 2133f30
Show file tree
Hide file tree
Showing 14 changed files with 691 additions and 27 deletions.
8 changes: 6 additions & 2 deletions js_modules/dagster-ui/packages/ui-core/src/app/Telemetry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {gql} from '../apollo-client';

export enum TelemetryAction {
LAUNCH_RUN = 'LAUNCH_RUN',
LAUNCH_MULTIPLE_RUNS = 'LAUNCH_MULTIPLE_RUNS',
GRAPHQL_QUERY_COMPLETED = 'GRAPHQL_QUERY_COMPLETED',
}

Expand Down Expand Up @@ -38,7 +39,7 @@ const LOG_TELEMETRY_MUTATION = gql`
export async function logTelemetry(
pathPrefix: string,
action: TelemetryAction,
metadata: {[key: string]: string | null | undefined} = {},
metadata: {[key: string]: string | string[] | null | undefined} = {},
) {
const graphqlPath = `${pathPrefix || ''}/graphql`;

Expand All @@ -63,7 +64,10 @@ export async function logTelemetry(
export const useTelemetryAction = () => {
const {basePath, telemetryEnabled} = useContext(AppContext);
return useCallback(
(action: TelemetryAction, metadata: {[key: string]: string | null | undefined} = {}) => {
(
action: TelemetryAction,
metadata: {[key: string]: string | string[] | null | undefined} = {},
) => {
if (telemetryEnabled) {
logTelemetry(basePath, action, metadata);
}
Expand Down
24 changes: 24 additions & 0 deletions js_modules/dagster-ui/packages/ui-core/src/graphql/schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions js_modules/dagster-ui/packages/ui-core/src/graphql/types.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {useCallback} from 'react';
import {useHistory} from 'react-router-dom';

import {useMutation} from '../apollo-client';
import {TelemetryAction, useTelemetryAction} from '../app/Telemetry';
import {showLaunchError} from '../launchpad/showLaunchError';
import {
LAUNCH_MULTIPLE_RUNS_MUTATION,
LaunchBehavior,
handleLaunchMultipleResult,
} from '../runs/RunUtils';
import {
LaunchMultipleRunsMutation,
LaunchMultipleRunsMutationVariables,
} from '../runs/types/RunUtils.types';

export function useLaunchMultipleRunsWithTelemetry() {
const [launchMultipleRuns] = useMutation<
LaunchMultipleRunsMutation,
LaunchMultipleRunsMutationVariables
>(LAUNCH_MULTIPLE_RUNS_MUTATION);

const logTelemetry = useTelemetryAction();
const history = useHistory();

return useCallback(
async (variables: LaunchMultipleRunsMutationVariables, behavior: LaunchBehavior) => {
const jobNames = variables.executionParamsList.map((params) => params.selector?.jobName);

if (
jobNames.length !== variables.executionParamsList.length ||
jobNames.includes(undefined)
) {
return;
}

const metadata: {[key: string]: string | string[] | null | undefined} = {
jobNames: jobNames.filter((name): name is string => name !== undefined),
opSelection: undefined,
};

let result;
try {
result = (await launchMultipleRuns({variables})).data?.launchMultipleRuns;
if (result) {
handleLaunchMultipleResult(result, history, {behavior});
logTelemetry(
TelemetryAction.LAUNCH_MULTIPLE_RUNS,
metadata as {[key: string]: string | string[] | null | undefined},
);
}

return result;
} catch (error) {
console.error('error', error);
showLaunchError(error as Error);
}
return undefined;
},
[history, launchMultipleRuns, logTelemetry],
);
}
104 changes: 103 additions & 1 deletion js_modules/dagster-ui/packages/ui-core/src/runs/RunUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {StepSelection} from './StepSelection';
import {TimeElapsed} from './TimeElapsed';
import {RunFragment} from './types/RunFragments.types';
import {RunTableRunFragment} from './types/RunTableRunFragment.types';
import {LaunchPipelineExecutionMutation, RunTimeFragment} from './types/RunUtils.types';
import {
LaunchMultipleRunsMutation,
LaunchPipelineExecutionMutation,
RunTimeFragment,
} from './types/RunUtils.types';
import {Mono} from '../../../ui-components/src';
import {gql} from '../apollo-client';
import {showCustomAlert} from '../app/CustomAlertProvider';
Expand Down Expand Up @@ -115,6 +119,73 @@ export async function handleLaunchResult(
}
}

export async function handleLaunchMultipleResult(
result: void | null | LaunchMultipleRunsMutation['launchMultipleRuns'],
history: History<unknown>,
options: {behavior: LaunchBehavior; preserveQuerystring?: boolean},
) {
if (!result) {
showCustomAlert({body: `No data was returned. Did dagster-webserver crash?`});
return;
}
const successfulRunIds: string[] = [];

// show corresponding toasts
if (result.__typename === 'LaunchMultipleRunsSuccess') {
for (const individualResult of result.runs) {
successfulRunIds.push(individualResult.run.id);

const pathname = `/runs/${individualResult.run.id}`;
const search = options.preserveQuerystring ? history.location.search : '';
const openInSameTab = () => history.push({pathname, search});

// using open with multiple runs will spam new tabs
if (options.behavior === 'open') {
openInSameTab();
} else {
// toast is more preferred
await showSharedToaster({
intent: 'success',
message: (
<div>
Launched run <Mono>{individualResult.run.id.slice(0, 8)}</Mono>
</div>
),
action: {
text: 'View',
href: history.createHref({pathname, search}),
},
});
}
document.dispatchEvent(new CustomEvent('run-launched'));
}
} else if (result.__typename === 'InvalidSubsetError') {
showCustomAlert({body: result.message});
} else if (result.__typename === 'PythonError') {
showCustomAlert({
title: 'Error',
body: <PythonErrorInfo error={result} />,
});
} else {
let message = `This multiple job launch cannot be executed with the provided config.`;

if ('errors' in result) {
message += ` Please fix the following errors:\n\n${result.errors
.map((error) => error.message)
.join('\n\n')}`;
}

showCustomAlert({body: message});
}

// link to runs page filtered to run IDs
const params = new URLSearchParams();
successfulRunIds.forEach((id) => params.append('q[]', `id:${id}`));

const queryString = `/runs?${params.toString()}`;
history.push(queryString);
}

function getBaseExecutionMetadata(run: RunFragment | RunTableRunFragment) {
const hiddenTagKeys: string[] = [DagsterTag.IsResumeRetry, DagsterTag.StepSelection];

Expand Down Expand Up @@ -204,6 +275,37 @@ export const LAUNCH_PIPELINE_EXECUTION_MUTATION = gql`
${PYTHON_ERROR_FRAGMENT}
`;

export const LAUNCH_MULTIPLE_RUNS_MUTATION = gql`
mutation LaunchMultipleRuns($executionParamsList: [ExecutionParams!]!) {
launchMultipleRuns(executionParamsList: $executionParamsList) {
... on LaunchMultipleRunsSuccess {
runs {
... on LaunchRunSuccess {
run {
id
jobName
}
}
}
}
... on PipelineNotFoundError {
message
}
... on InvalidSubsetError {
message
}
... on RunConfigValidationInvalid {
errors {
message
}
}
...PythonErrorFragment
}
}
${PYTHON_ERROR_FRAGMENT}
`;

export const DELETE_MUTATION = gql`
mutation Delete($runId: String!) {
deletePipelineRun(runId: $runId) {
Expand Down
Loading

0 comments on commit 2133f30

Please sign in to comment.