feat(frontend): Schedules run now (#1475)

* feat(frontend): run now

* feat(frontend): run now

* feat(frontend): add missing await + add toast action to view run page

* feat(frontend): fix path

* feat(frontend): fix path
This commit is contained in:
Faton Ramadani
2023-04-25 14:47:13 +02:00
committed by GitHub
parent 4ae4035ea9
commit 3b36277757
@@ -1,5 +1,5 @@
<script lang="ts">
import { ScheduleService, type Schedule } from '$lib/gen'
import { ScheduleService, type Schedule, JobService, type ScriptArgs } from '$lib/gen'
import { canWrite, displayDate, sendUserToast } from '$lib/utils'
import CenteredPage from '$lib/components/CenteredPage.svelte'
@@ -17,6 +17,7 @@
faCircle,
faEdit,
faList,
faPlay,
faPlus,
faShare,
faToggleOff,
@@ -24,6 +25,7 @@
faTrash
} from '@fortawesome/free-solid-svg-icons'
import { Icon } from 'svelte-awesome'
import { goto } from '$app/navigation'
type ScheduleW = Schedule & { canWrite: boolean }
@@ -52,6 +54,31 @@
}
}
async function runScheduleNow(
path: string,
args: ScriptArgs | undefined,
isFlow: boolean
): Promise<void> {
try {
const runByPath = isFlow ? JobService.runFlowByPath : JobService.runScriptByPath
const run = await runByPath({
path,
requestBody: args ?? {},
workspace: $workspaceStore!
})
sendUserToast(`Schedule ${path} will run now`, false, [
{
label: 'Go to the run page',
callback: () => goto('/run/' + run + '?workspace=' + $workspaceStore)
}
])
} catch (err) {
sendUserToast(`Cannot run schedule now: ${err.body}`, true)
}
}
$: {
if ($workspaceStore && $userStore) {
loadSchedules()
@@ -87,7 +114,7 @@
<th />
</tr>
<tbody slot="body">
{#each schedules as { path, error, edited_by, edited_at, schedule, timezone, enabled, script_path, is_flow, extra_perms, canWrite }}
{#each schedules as { path, error, edited_by, edited_at, schedule, timezone, enabled, script_path, is_flow, extra_perms, canWrite, args }}
<tr class={enabled ? '' : 'bg-gray-50'}>
<td class="!px-0 text-center">
<SharedBadge {canWrite} extraPerms={extra_perms} />
@@ -208,6 +235,13 @@
icon: faList,
href: '/runs/' + path
},
{
displayName: 'Run now',
icon: faPlay,
action: () => {
runScheduleNow(script_path, args, is_flow)
}
},
{
displayName: canWrite ? 'Share' : 'See Permissions',
icon: faShare,