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

Trigger Schedule immediately #1682

Merged
merged 6 commits into from
Oct 13, 2023
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
24 changes: 5 additions & 19 deletions src/lib/components/schedule/schedule-advanced-settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,12 @@
</p>
{#if state?.limitedActions}
<p>
{translate('schedules', 'start-time')}
{spec?.startTime ?? translate('none')}
</p>
<p>
{translate('schedules', 'end-time')}{spec?.endTime ?? translate('none')}
</p>
<p>{translate('schedules', 'jitter')}{spec?.jitter ?? translate('none')}</p>
<p>
{translate('schedules', 'exclusion-calendar')}{spec
?.excludeCalendar?.[0] ?? translate('none')}
</p>
{#if state?.limitedActions}
<p>
{translate('schedules', 'remaining-actions')}{state?.remainingActions ??
translate('none')}
</p>
{/if}
<p>
{translate('schedules', 'overlap-policy')}{policies?.overlapPolicy ??
{translate('schedules', 'remaining-actions')}{state?.remainingActions ??
translate('none')}
</p>
{/if}
<p>
{translate('schedules', 'overlap-policy')}{policies?.overlapPolicy ??
translate('none')}
</p>
</Accordion>
43 changes: 28 additions & 15 deletions src/lib/holocene/radio-input/radio-input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
export let value: T;
export let id: string;
export let label: string;
export let description: string | undefined = undefined;
export let labelHidden = false;

let internalGroup: Writable<T> = writable(value);
Expand All @@ -29,27 +30,39 @@
const { name, group } = ctx;
</script>

<label>
<input
bind:group={$group}
type="radio"
{name}
{value}
{id}
{...$$restProps}
/>
<span class="label" class:hidden={labelHidden}>
{label}
</span>
</label>
<div class="flex flex-col gap-1">
<label>
<input
bind:group={$group}
type="radio"
aria-describedby="{id}-description"
{name}
{value}
{id}
{...$$restProps}
/>
<span class="label" class:hidden={labelHidden}>
{label}
</span>
</label>
{#if description}
<p class="description" id="{id}-description">
{description}
</p>
{/if}
</div>

<style lang="postcss">
.description {
@apply ml-[26px] text-xs font-light;
}

label {
@apply flex grow cursor-pointer flex-row items-center gap-1 text-sm focus:outline-none;
@apply flex grow cursor-pointer flex-row items-center gap-2 text-sm font-normal focus:outline-none;
}

input[type='radio'] {
@apply relative box-content h-4 w-4 cursor-pointer appearance-none rounded-full border border-gray-300 bg-white;
@apply relative box-content h-4 w-4 min-w-[16px] cursor-pointer appearance-none rounded-full border border-gray-300 bg-white;

&::after {
@apply absolute top-1 left-1 h-0 w-0 scale-0 rounded-full bg-white transition-transform content-[''];
Expand Down
1 change: 1 addition & 0 deletions src/lib/holocene/radio-input/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface RadioInputProps<T> extends HTMLInputAttributes {
id: string;
label: string;
labelHidden?: boolean;
description?: string;
group?: Writable<T>;
name?: string;
'data-testid'?: string;
Expand Down
22 changes: 22 additions & 0 deletions src/lib/i18n/locales/en/schedules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ export const Strings = {
'unpause-modal-confirmation':
'Are you sure you want to unpause {{schedule}}?',
'unpause-reason': 'Enter a reason for unpausing the schedule.',
trigger: 'Trigger',
'trigger-modal-title': 'Trigger Immediately',
'trigger-unspecified-title': 'Use Policy',
'trigger-unspecified-description': "Use the Schedule's overlap policy.",
'trigger-skip-title': 'Skip',
'trigger-skip-description':
'When the workflow completes, the next occurrence that is scheduled after that time is considered.',
'trigger-buffer-one-title': 'Buffer One',
'trigger-buffer-one-description':
'Start the workflow again as soon as the current workflow completes, but buffer only one start. If another start is scheduled to happen while the workflow is running, and a workflow is already buffered, only the first workflow starts after the running workflow completes.',
'trigger-buffer-all-title': 'Buffer All',
'trigger-buffer-all-description':
'Buffer any number of workflow starts to happen sequentially, beginning immediately after the running workflow completes.',
'trigger-cancel-other-title': 'Cancel Other',
'trigger-cancel-other-description':
'If another workflow is running, cancel it. After the previous workflow completes cancellation, start the new workflow.',
'trigger-terminate-other-title': 'Terminate Other',
'trigger-terminate-other-description':
'If another workflow is running, terminate it and start the new workflow immediately.',
'trigger-allow-all-title': 'Allow All',
'trigger-allow-all-description':
"Start any number of concurrent workflows. Last completion result and last failure aren't available because the workflows aren't sequential.",
'delete-modal-title': 'Delete Schedule?',
'delete-modal-confirmation': 'Are you sure you want to delete {{schedule}}?',
'advanced-settings': 'Advanced Settings ',
Expand Down
117 changes: 107 additions & 10 deletions src/lib/pages/schedule-view.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script lang="ts">
import { writable } from 'svelte/store';

import { goto } from '$app/navigation';
import { page } from '$app/stores';

Expand All @@ -12,17 +14,21 @@
import Loading from '$lib/holocene/loading.svelte';
import MenuItem from '$lib/holocene/menu/menu-item.svelte';
import Modal from '$lib/holocene/modal.svelte';
import RadioGroup from '$lib/holocene/radio-input/radio-group.svelte';
import RadioInput from '$lib/holocene/radio-input/radio-input.svelte';
import SplitButton from '$lib/holocene/split-button.svelte';
import { translate } from '$lib/i18n/translate';
import {
deleteSchedule,
fetchSchedule,
pauseSchedule,
triggerImmediately,
unpauseSchedule,
} from '$lib/services/schedule-service';
import { coreUserStore } from '$lib/stores/core-user';
import { loading } from '$lib/stores/schedules';
import { relativeTime, timeFormat } from '$lib/stores/time-format';
import type { OverlapPolicy } from '$lib/types/schedule';
import { decodeURIForSvelte } from '$lib/utilities/encode-uri';
import { formatDate } from '$lib/utilities/format-date';
import {
Expand All @@ -43,9 +49,53 @@
let scheduleFetch = fetchSchedule(parameters);

let pauseConfirmationModalOpen = false;
let triggerConfirmationModalOpen = false;
let deleteConfirmationModalOpen = false;
let reason = '';
let error = '';
let triggerLoading = false;
let overlapPolicy = writable<OverlapPolicy>('Unspecified');
let policies: { label: string; description: string; value: OverlapPolicy }[] =
[
{
description: translate('schedules', 'trigger-unspecified-description'),
label: translate('schedules', 'trigger-unspecified-title'),
value: 'Unspecified',
},
{
description: translate('schedules', 'trigger-allow-all-description'),
label: translate('schedules', 'trigger-allow-all-title'),
value: 'AllowAll',
},
{
description: translate('schedules', 'trigger-skip-description'),
label: translate('schedules', 'trigger-skip-title'),
value: 'Skip',
},
{
description: translate('schedules', 'trigger-buffer-one-description'),
label: translate('schedules', 'trigger-buffer-one-title'),
value: 'BufferOne',
},
{
description: translate('schedules', 'trigger-buffer-all-description'),
label: translate('schedules', 'trigger-buffer-all-title'),
value: 'BufferAll',
},
{
description: translate('schedules', 'trigger-cancel-other-description'),
label: translate('schedules', 'trigger-cancel-other-title'),
value: 'CancelOther',
},
{
description: translate(
'schedules',
'trigger-terminate-other-description',
),
label: translate('schedules', 'trigger-terminate-other-title'),
value: 'TerminateOther',
},
];

let coreUser = coreUserStore();
let editDisabled = $coreUser.namespaceWriteDisabled(namespace);
Expand Down Expand Up @@ -86,6 +136,20 @@
pauseConfirmationModalOpen = false;
};

const handleTriggerImmediately = async () => {
triggerLoading = true;
await triggerImmediately({
namespace,
scheduleId,
overlapPolicy: $overlapPolicy,
});
setTimeout(() => {
scheduleFetch = fetchSchedule(parameters, fetch);
triggerConfirmationModalOpen = false;
triggerLoading = false;
}, 1000);
};

const resetReason = () => {
reason = '';
};
Expand Down Expand Up @@ -119,7 +183,7 @@
<Loading title={translate('schedules', 'deleting')} class="my-2" />
{:else}
<header class="mb-8 flex flex-row justify-between gap-4">
<div class="relative flex flex-col gap-1">
<div class="relative flex flex-col gap-4">
<Link
on:click={() => {
goto(routeForSchedules({ namespace }));
Expand All @@ -128,19 +192,15 @@
>
{translate('schedules', 'back-to-schedules')}
</Link>
<h1 class="relative mt-8 flex items-center gap-4 text-2xl">
<WorkflowStatus
status={schedule?.schedule.state.paused ? 'Paused' : 'Running'}
/>
<h1 class="relative mt-4 flex items-center text-2xl">
<span class="select-all font-medium" data-testid="schedule-name">
{scheduleId}
</span>
</h1>
<div class="flex items-center gap-2 text-sm">
<p>
{namespace}
</p>
<div class="h-1 w-1 rounded-full bg-gray-900" />
<div class="flex items-center gap-2 text-lg">
<WorkflowStatus
status={schedule?.schedule.state.paused ? 'Paused' : 'Running'}
/>
<p>
{schedule?.schedule?.action?.startWorkflow?.workflowType?.name}
</p>
Expand Down Expand Up @@ -176,6 +236,12 @@
disabled={editDisabled}
on:click={() => (pauseConfirmationModalOpen = true)}
>
<MenuItem
data-testid="trigger-schedule"
on:click={() => (triggerConfirmationModalOpen = true)}
>
{translate('schedules', 'trigger')}
</MenuItem>
<MenuItem
data-testid="edit-schedule"
href={routeForScheduleEdit({ namespace, scheduleId })}
Expand Down Expand Up @@ -261,6 +327,37 @@
/>
</div>
</Modal>
<Modal
id="trigger-schedule-modal"
large
bind:open={triggerConfirmationModalOpen}
confirmType="primary"
confirmText={translate('schedules', 'trigger')}
cancelText={translate('cancel')}
loading={triggerLoading}
on:confirmModal={() => handleTriggerImmediately()}
on:cancelModal={() => (triggerConfirmationModalOpen = false)}
>
<h3 slot="title">
{translate('schedules', 'trigger-modal-title')}
</h3>
<div slot="content">
<RadioGroup
group={overlapPolicy}
name="trigger-event-id"
class="h-auto overflow-auto"
>
{#each policies as policy}
<RadioInput
id={policy.value}
value={policy.value}
label={policy.label}
description={policy.description}
/>
{/each}
</RadioGroup>
</div>
</Modal>
<Modal
id="delete-schedule-modal"
bind:open={deleteConfirmationModalOpen}
Expand Down
36 changes: 35 additions & 1 deletion src/lib/services/schedule-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
ScheduleListEntry,
UpdateScheduleRequest,
} from '$lib/types';
import type { DescribeFullSchedule } from '$lib/types/schedule';
import type { DescribeFullSchedule, OverlapPolicy } from '$lib/types/schedule';
import { stringifyWithBigInt } from '$lib/utilities/parse-with-big-int';
import type { ErrorCallback } from '$lib/utilities/request-from-api';
import { requestFromAPI } from '$lib/utilities/request-from-api';
Expand Down Expand Up @@ -204,3 +204,37 @@ export async function unpauseSchedule({
},
});
}

type TriggerImmediatelyOptions = {
namespace: string;
scheduleId: string;
overlapPolicy: OverlapPolicy;
};

export async function triggerImmediately({
namespace,
scheduleId,
overlapPolicy,
}: TriggerImmediatelyOptions): Promise<null> {
const options = {
patch: {
triggerImmediately: {
overlapPolicy,
},
},
};

const route = routeForApi('schedule', {
namespace,
scheduleId: scheduleId,
});
return await requestFromAPI<null>(route, {
options: {
method: 'PATCH',
body: stringifyWithBigInt({
...options,
request_id: uuidv4(),
}),
},
});
}
9 changes: 9 additions & 0 deletions src/lib/types/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,12 @@ export type ScheduleParameters = ScheduleActionParameters &
SchedulePresetsParameters;

export type ScheduleStatus = 'Paused' | 'Running';

export type OverlapPolicy =
| 'Unspecified'
| 'Skip'
| 'BufferOne'
| 'BufferAll'
| 'CancelOther'
| 'TerminateOther'
| 'AllowAll';
Loading