From 0411af7d491e2c59534aba687bb1b8553c242299 Mon Sep 17 00:00:00 2001
From: Arman
Date: Mon, 10 Mar 2025 13:00:14 +0100
Subject: [PATCH] feat: executions
---
src/lib/components/viewSelector.svelte | 16 +-
src/lib/helpers/types.ts | 1 +
.../executions/+page.svelte | 170 +------
.../function-[function]/executions/+page.ts | 5 +-
.../executions/execute-function/+page.svelte | 464 ++++++++----------
.../executions/execute-function/+page.ts | 4 +-
.../executions/execute-function/aside.svelte | 84 ++++
.../executions/quickFilters.svelte | 3 -
.../executions/sheet.svelte | 132 +++++
.../function-[function]/executions/store.ts | 122 +++++
.../executions/table.svelte | 202 ++++----
11 files changed, 671 insertions(+), 532 deletions(-)
create mode 100644 src/routes/(console)/project-[project]/functions/function-[function]/executions/execute-function/aside.svelte
create mode 100644 src/routes/(console)/project-[project]/functions/function-[function]/executions/sheet.svelte
create mode 100644 src/routes/(console)/project-[project]/functions/function-[function]/executions/store.ts
diff --git a/src/lib/components/viewSelector.svelte b/src/lib/components/viewSelector.svelte
index 564f2bff4..04afafc9b 100644
--- a/src/lib/components/viewSelector.svelte
+++ b/src/lib/components/viewSelector.svelte
@@ -75,12 +75,14 @@
});
}
- $: selectedColumnsNumber = $columns.reduce((acc, column) => {
- if (column.show) {
- acc++;
- }
- return acc;
- }, 0);
+ $: selectedColumnsNumber = $columns
+ .filter((c) => !c.hide)
+ .reduce((acc, column) => {
+ if (column.show) {
+ acc++;
+ }
+ return acc;
+ }, 0);
{#if !hideColumns && view === View.Table}
@@ -96,7 +98,7 @@
- {#each $columns as column}
+ {#each $columns.filter((c) => !c.hide) as column}
>(
diff --git a/src/routes/(console)/project-[project]/functions/function-[function]/executions/+page.svelte b/src/routes/(console)/project-[project]/functions/function-[function]/executions/+page.svelte
index 980a3cf4b..f44dccf92 100644
--- a/src/routes/(console)/project-[project]/functions/function-[function]/executions/+page.svelte
+++ b/src/routes/(console)/project-[project]/functions/function-[function]/executions/+page.svelte
@@ -1,141 +1,22 @@
@@ -181,23 +57,26 @@
-->
-
+ {#if data?.executions?.total}
+
+ {/if}
- {#if !$func.logging}
+ {#if !data.func.logging}
Your execution logs are disabled
To view execution logs and errors, enable them in your
Function settings.
@@ -205,7 +84,7 @@
{/if}
{#if data?.executions?.total}
-
+
{:else if data?.query}
-
-
-
-
Sorry we couldn't find any executions
-
There are no executions that match your filters.
-
-
-
-
-
-
+
{:else}
goto(
- `${base}/project-${$project.$id}/functions/function-${$func.$id}/executions/execute-function`
+ `${base}/project-${$project.$id}/functions/function-${data.func.$id}/executions/execute-function`
)}>
{/if}
diff --git a/src/routes/(console)/project-[project]/functions/function-[function]/executions/+page.ts b/src/routes/(console)/project-[project]/functions/function-[function]/executions/+page.ts
index 2d4d66858..6f2190057 100644
--- a/src/routes/(console)/project-[project]/functions/function-[function]/executions/+page.ts
+++ b/src/routes/(console)/project-[project]/functions/function-[function]/executions/+page.ts
@@ -5,7 +5,9 @@ import { Dependencies, PAGE_LIMIT } from '$lib/constants';
import type { PageLoad } from './$types';
import { queries, queryParamToMap } from '$lib/components/filters';
-export const load: PageLoad = async ({ params, depends, url, route }) => {
+export const load: PageLoad = async ({ params, depends, url, route, parent }) => {
+ const { function: func } = await parent();
+
depends(Dependencies.EXECUTIONS);
const page = getPage(url);
const limit = getLimit(url, route, PAGE_LIMIT);
@@ -19,6 +21,7 @@ export const load: PageLoad = async ({ params, depends, url, route }) => {
offset,
limit,
query,
+ func,
executions: await sdk.forProject.functions.listExecutions(params.function, [
Query.limit(limit),
Query.offset(offset),
diff --git a/src/routes/(console)/project-[project]/functions/function-[function]/executions/execute-function/+page.svelte b/src/routes/(console)/project-[project]/functions/function-[function]/executions/execute-function/+page.svelte
index c2f4fb73d..f63e4302d 100644
--- a/src/routes/(console)/project-[project]/functions/function-[function]/executions/execute-function/+page.svelte
+++ b/src/routes/(console)/project-[project]/functions/function-[function]/executions/execute-function/+page.svelte
@@ -3,31 +3,21 @@
import { base } from '$app/paths';
import { page } from '$app/stores';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
- import { timer } from '$lib/actions/timer';
- import { Alert, Card, Id } from '$lib/components';
-
import { Dependencies } from '$lib/constants';
- import { Pill } from '$lib/elements';
import {
Button,
Form,
- FormList,
Helper,
InputDate,
InputSelect,
- InputSelectSearch,
InputText,
InputTextarea,
InputTime
} from '$lib/elements/forms';
- import { humanFileSize } from '$lib/helpers/sizeConvertion';
- import { calculateTime } from '$lib/helpers/timeConversion';
- import { WizardSecondaryContent, WizardSecondaryFooter } from '$lib/layout';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { ExecutionMethod, type Models } from '@appwrite.io/console';
import { writable } from 'svelte/store';
- import { proxyRuleList } from '../../store';
import {
isSameDay,
toLocaleDateISO,
@@ -35,10 +25,19 @@
toLocaleTimeISO
} from '$lib/helpers/date';
import { last } from '$lib/helpers/array';
- import { Icon, Tooltip } from '@appwrite.io/pink-svelte';
- import { IconPlus } from '@appwrite.io/pink-icons-svelte';
+ import {
+ Accordion,
+ Alert,
+ Fieldset,
+ Icon,
+ Input,
+ Layout,
+ Tooltip,
+ Typography
+ } from '@appwrite.io/pink-svelte';
+ import { IconInfo, IconPlus, IconX } from '@appwrite.io/pink-icons-svelte';
import Wizard from '$lib/layout/wizard.svelte';
- import { DeploymentCreatedBy, DeploymentDomains, DeploymentSource } from '$lib/components/git';
+ import Aside from './aside.svelte';
let previousPage: string = `${base}/project-${$page.params.project}/functions/function-${$page.params.function}/executions`;
@@ -140,258 +139,221 @@
- Execute function - Appwrite
+ Create execution - Appwrite
-
- Execute function
-
-
+
+
+ {:else}
+
+
+
-
-
- Total size
-
- {humanFileSize(deployment.sourceSize + deployment.buildSize).value +
- humanFileSize(deployment.sourceSize + deployment.buildSize).unit}
-
-
-
-
- Deployment size:
- {humanFileSize(deployment.sourceSize).value +
- humanFileSize(deployment.sourceSize).unit}
-
-
- Build size:
- {humanFileSize(deployment.buildSize).value +
- humanFileSize(deployment.buildSize).unit}
-
-
-
-
-
-
-
- {#if $proxyRuleList?.rules?.length}
-
- {/if}
-
-
-
-
+
+ {#if isScheduled}
+
+
+
+
+
+
+ Your function will be executed on {toLocaleDateTime(
+ dateTime?.toString()
+ )}
+
+
+ {/if}
+
+
+ {/if}
+
+
+
+
+
-
+
-
+
diff --git a/src/routes/(console)/project-[project]/functions/function-[function]/executions/execute-function/+page.ts b/src/routes/(console)/project-[project]/functions/function-[function]/executions/execute-function/+page.ts
index 1d11c6734..25eecd72e 100644
--- a/src/routes/(console)/project-[project]/functions/function-[function]/executions/execute-function/+page.ts
+++ b/src/routes/(console)/project-[project]/functions/function-[function]/executions/execute-function/+page.ts
@@ -1,6 +1,7 @@
import { sdk } from '$lib/stores/sdk';
import { Dependencies } from '$lib/constants';
import type { PageLoad } from './$types';
+import { proxyRuleList } from '../../store';
export const load: PageLoad = async ({ params, depends, parent }) => {
const data = await parent();
@@ -13,6 +14,7 @@ export const load: PageLoad = async ({ params, depends, parent }) => {
params.function,
data.function.deployment
)
- : null
+ : null,
+ proxyRuleList: data.proxyRuleList
};
};
diff --git a/src/routes/(console)/project-[project]/functions/function-[function]/executions/execute-function/aside.svelte b/src/routes/(console)/project-[project]/functions/function-[function]/executions/execute-function/aside.svelte
new file mode 100644
index 000000000..4c38b622a
--- /dev/null
+++ b/src/routes/(console)/project-[project]/functions/function-[function]/executions/execute-function/aside.svelte
@@ -0,0 +1,84 @@
+
+
+
+
+
+
+
+ Deployment ID
+
+
+ {deployment.$id}
+
+
+
+
+ Build duration
+
+ {#if ['processing', 'building'].includes(deployment.status)}
+
+ {:else}
+ {formatTimeDetailed(deployment.buildDuration)}
+ {/if}
+
+
+
+ Size
+
+
+ {humanFileSize(deployment.sourceSize + deployment.buildSize).value +
+ humanFileSize(deployment.sourceSize + deployment.buildSize).unit}
+
+
+
+
+ Deployment size:
+ {humanFileSize(deployment.sourceSize).value +
+ humanFileSize(deployment.sourceSize).unit}
+
+
+ Build size:
+ {humanFileSize(deployment.buildSize).value +
+ humanFileSize(deployment.buildSize).unit}
+
+
+
+
+
+
+
+ Source
+
+
+
+
+ {#if proxyRuleList?.total}
+
+ Domains
+
+
+
+
+ {/if}
+
+
+ Updated
+
+
+
+
+
+
+
diff --git a/src/routes/(console)/project-[project]/functions/function-[function]/executions/quickFilters.svelte b/src/routes/(console)/project-[project]/functions/function-[function]/executions/quickFilters.svelte
index 65bb31ee2..df451a731 100644
--- a/src/routes/(console)/project-[project]/functions/function-[function]/executions/quickFilters.svelte
+++ b/src/routes/(console)/project-[project]/functions/function-[function]/executions/quickFilters.svelte
@@ -1,18 +1,15 @@
+
+
+
+
+
+ Log ID
+
+ {selectedLog?.$id}
+
+
+
+
+
+
+
+
+ {#if selectedLog}
+
+
+
+
+
+
+
+ Method
+
+
+ {selectedLog.requestMethod}
+
+
+
+
+ Status
+
+
+ = 400
+ ? 'error'
+ : 'success'} />
+
+
+
+
+ Duration
+
+
+ {calculateTime(selectedLog.duration)}
+
+
+
+
+ Created
+
+
+ {capitalize(timeFromNow(selectedLog.$createdAt))}
+
+
+
+
+
+
+
+ Path
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {/if}
+
diff --git a/src/routes/(console)/project-[project]/functions/function-[function]/executions/store.ts b/src/routes/(console)/project-[project]/functions/function-[function]/executions/store.ts
new file mode 100644
index 000000000..2459b8059
--- /dev/null
+++ b/src/routes/(console)/project-[project]/functions/function-[function]/executions/store.ts
@@ -0,0 +1,122 @@
+import type { Column } from '$lib/helpers/types';
+import { writable } from 'svelte/store';
+
+export const columns = writable([
+ { id: '$id', title: 'Execution ID', type: 'string', show: true, width: 150 },
+
+ {
+ id: '$createdAt',
+ title: 'Created',
+ type: 'datetime',
+ show: true,
+ width: 120,
+ format: 'datetime',
+ elements: [
+ {
+ value: 5 * 60 * 1000,
+ label: 'last 5 minutes'
+ },
+ {
+ value: 60 * 60 * 1000,
+ label: 'last 1 hour'
+ },
+ {
+ value: 24 * 60 * 60 * 1000,
+ label: 'last 24 hours'
+ }
+ ]
+ },
+ {
+ id: 'trigger',
+ title: 'Trigger',
+ type: 'string',
+ show: false,
+ width: 90,
+ array: true,
+ format: 'enum',
+ elements: [
+ { value: 'http', label: 'HTTP' },
+ { value: 'schedule', label: 'Schedule' },
+ { value: 'event', label: 'Event' }
+ ],
+ hide: true
+ },
+ {
+ id: 'requestMethod',
+ title: 'Method',
+ type: 'string',
+ show: false,
+ width: 70,
+ array: true,
+ format: 'enum',
+ elements: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
+ hide: true
+ },
+ {
+ id: 'responseStatusCode',
+ title: 'Status code',
+ type: 'integer',
+ show: false,
+ width: 100,
+ format: 'integer',
+ elements: [
+ {
+ value: 299,
+ label: 'Success (200-299)'
+ },
+ {
+ value: 399,
+ label: 'Redirect (300-399)'
+ },
+ {
+ value: 499,
+ label: 'Client error (400-499)'
+ },
+ {
+ value: 599,
+ label: 'Server error (500-599)'
+ }
+ ],
+ hide: true
+ },
+ {
+ id: 'requestPath',
+ title: 'Path',
+ type: 'string',
+ show: true,
+ width: 90,
+ format: 'string'
+ },
+ {
+ id: 'status',
+ title: 'Status',
+ type: 'enum',
+ show: true,
+ width: 130,
+ array: true,
+ format: 'enum',
+ elements: ['completed', 'failed', 'waiting', 'scheduled', 'processing', 'cancelled']
+ },
+ {
+ id: 'duration',
+ title: 'Duration',
+ type: 'integer',
+ show: true,
+ width: 80,
+ format: 'integer',
+ elements: [
+ {
+ value: 1,
+ label: 'more than 1 second'
+ },
+ {
+ value: 5,
+ label: 'more than 5 seconds'
+ },
+ {
+ value: 30,
+ label: 'more than 30 seconds'
+ }
+ ]
+ }
+]);
diff --git a/src/routes/(console)/project-[project]/functions/function-[function]/executions/table.svelte b/src/routes/(console)/project-[project]/functions/function-[function]/executions/table.svelte
index 71105e69a..59be85c6a 100644
--- a/src/routes/(console)/project-[project]/functions/function-[function]/executions/table.svelte
+++ b/src/routes/(console)/project-[project]/functions/function-[function]/executions/table.svelte
@@ -1,154 +1,124 @@
{#each columns as column}
- {#if column.show}
- {column.title}
+ {#if column.show && !column.hide}
+ {column.title}
{/if}
{/each}
-
- {#each data.executions.executions as execution, index (execution.$id)}
-
+ {#each logs.executions as log}
+ {
+ openSheet = true;
+ selectedLogId = log.$id;
+ }}>
{#each columns as column}
- {#if column.show}
+ {#if column.show && !column.hide}
{#if column.id === '$id'}
{#key column.id}
- {execution.$id}
+ {log.$id}
{/key}
- {:else if column.id === 'status'}
-
- {@const status = execution.status}
-
-
-
- {#if status === 'scheduled'}
-
- {timeFromNow(execution.scheduledAt)}
- {:else}
- {status}
- {/if}
-
-
- {`Scheduled to execute on ${toLocaleDateTime(execution.scheduledAt)}`}
-
-
{:else if column.id === '$createdAt'}
- {timeFromNow(execution.$createdAt)}
-
- {:else if column.id === 'trigger'}
-
-
- {execution.trigger}
-
-
- {:else if column.id === 'requestMethod'}
-
- {execution.requestMethod}
-
- {:else if column.id === 'responseStatusCode'}
-
- {execution.responseStatusCode}
+ {capitalize(timeFromNow(log.$createdAt))}
{:else if column.id === 'requestPath'}
- {execution.requestPath}
+
+ = 400
+ ? 'error'
+ : log.responseStatusCode === 0
+ ? undefined
+ : 'success'}
+ content={log.responseStatusCode.toString()} />
+
+ {log.requestMethod}
+
+
+ {log.requestPath}
+
+
+
+ {:else if column.id === 'responseStatusCode'}
+
+ {log.responseStatusCode}
+
+ {:else if column.id === 'status'}
+
+ {@const status = log.status}
+
+
+
+ {#if status === 'scheduled'}
+
+ {timeFromNow(log.scheduledAt)}
+ {:else}
+ {status}
+ {/if}
+
+
+
+ {`Scheduled to execute on ${toLocaleDateTime(log.scheduledAt)}`}
+
+
{:else if column.id === 'duration'}
- {calculateTime(execution.duration)}
+ {formatTimeDetailed(log.duration)}
{/if}
{/if}
{/each}
-
-
-
-
- {
- showDropdown = [];
- showLogs(execution);
- }}>
- Logs
-
- {
- selectedExecution = execution;
- showDropdown = [];
- showDelete = true;
- }}>
- Delete
-
-
-
-
-
+
{/each}
-{#if selectedExecution}
-
-{/if}
+