fix: try catch functions

This commit is contained in:
Arman
2023-08-18 17:33:34 +02:00
parent 6f1847d3d5
commit f784c05404
9 changed files with 153 additions and 118 deletions
+1
View File
@@ -187,6 +187,7 @@ export enum Submit {
FunctionUpdateLogging = 'submit_function_update_logging',
FunctionUpdateTimeout = 'submit_function_update_timeout',
FunctionUpdateEvents = 'submit_function_update_events',
FunctionConnectRepo = 'submit_function_disconnect_repo',
FunctionDisconnectRepo = 'submit_function_disconnect_repo',
FunctionRedeploy = 'submit_function_redeploy',
DeploymentCreate = 'submit_deployment_create',
@@ -16,7 +16,7 @@
export let hasInstallations = false;
export let action: 'button' | 'select' = 'select';
let offset = 0;
const limit = 1;
const limit = 5;
$: {
hasInstallations = $installations?.total > 0;
@@ -9,29 +9,42 @@
import { wizard } from '$lib/stores/wizard';
import { invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
import { addNotification } from '$lib/stores/notifications';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
async function createGitHubInstallation() {
await sdk.forProject.functions.update(
$func.$id,
$func.name,
$func.runtime,
$func.entrypoint || undefined,
$func.execute || undefined,
$func.events || undefined,
$func.schedule || undefined,
$func.timeout || undefined,
$func.enabled || undefined,
$func.logging || undefined,
$func.commands || undefined,
$installation.$id,
$repository.id,
$choices.branch,
$choices.silentMode,
$choices.rootDir
);
await invalidate(Dependencies.FUNCTION);
resetState();
wizard.hide();
try {
await sdk.forProject.functions.update(
$func.$id,
$func.name,
$func.runtime,
$func.entrypoint || undefined,
$func.execute || undefined,
$func.events || undefined,
$func.schedule || undefined,
$func.timeout || undefined,
$func.enabled || undefined,
$func.logging || undefined,
$func.commands || undefined,
$installation.$id,
$repository.id,
$choices.branch,
$choices.silentMode,
$choices.rootDir
);
trackEvent(Submit.FunctionConnectRepo, {
customId: !!$func.$id
});
await invalidate(Dependencies.FUNCTION);
resetState();
wizard.hide();
} catch (error) {
addNotification({
message: error.message,
type: 'error'
});
trackError(error, Submit.FunctionConnectRepo);
}
}
function resetState() {
+39 -29
View File
@@ -7,7 +7,7 @@
import { goto } from '$app/navigation';
import { choices, createFunction, installation, repository } from './store';
import { addNotification } from '$lib/stores/notifications';
import { Submit, trackEvent } from '$lib/actions/analytics';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { base } from '$app/paths';
import { page } from '$app/stores';
import ExecuteAccess from './steps/executeAccess.svelte';
@@ -15,34 +15,44 @@
import FunctionConfiguration from './steps/functionConfiguration.svelte';
async function create() {
const response = await sdk.forProject.functions.create(
$createFunction.$id || ID.unique(),
$createFunction.name,
$createFunction.runtime,
$createFunction.entrypoint,
$createFunction.execute || undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
$createFunction.commands || undefined,
$installation.$id,
$repository.id,
$choices.branch,
$choices.silentMode || undefined,
$choices.rootDir || undefined
);
goto(`${base}/console/project-${$page.params.project}/functions/function-${response.$id}`);
addNotification({
message: `${$createFunction.name} has been created`,
type: 'success'
});
trackEvent(Submit.FunctionCreate, {
customId: !!$createFunction.$id
});
resetState();
wizard.hide();
try {
const response = await sdk.forProject.functions.create(
$createFunction.$id || ID.unique(),
$createFunction.name,
$createFunction.runtime,
$createFunction.entrypoint,
$createFunction.execute || undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
$createFunction.commands || undefined,
$installation.$id,
$repository.id,
$choices.branch,
$choices.silentMode || undefined,
$choices.rootDir || undefined
);
goto(
`${base}/console/project-${$page.params.project}/functions/function-${response.$id}`
);
addNotification({
message: `${$createFunction.name} has been created`,
type: 'success'
});
trackEvent(Submit.FunctionCreate, {
customId: !!$createFunction.$id
});
resetState();
wizard.hide();
} catch (error) {
addNotification({
message: error.message,
type: 'error'
});
trackError(error, Submit.FunctionCreate);
}
}
function resetState() {
@@ -13,7 +13,7 @@
repository
} from './store';
import { addNotification } from '$lib/stores/notifications';
import { Submit, trackEvent } from '$lib/actions/analytics';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { base } from '$app/paths';
import { page } from '$app/stores';
import Details from './steps/details.svelte';
@@ -57,6 +57,7 @@
message: error.message,
type: 'error'
});
trackError(error, Submit.FunctionCreate);
}
}
+51 -41
View File
@@ -7,7 +7,7 @@
import { goto } from '$app/navigation';
import { choices, installation, repository, template, templateConfig } from './store';
import { addNotification } from '$lib/stores/notifications';
import { Submit, trackEvent } from '$lib/actions/analytics';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { base } from '$app/paths';
import { page } from '$app/stores';
import GitConfiguration from './steps/gitConfiguration.svelte';
@@ -18,49 +18,59 @@
import { scopes } from '$lib/constants';
async function create() {
const runtimeDetail = $template.runtimes.find((r) => r.name === $templateConfig.runtime);
try {
const runtimeDetail = $template.runtimes.find(
(r) => r.name === $templateConfig.runtime
);
const key = await sdk.forConsole.projects.createKey(
$page.params.project,
'Generated for Template',
scopes.map((scope) => scope.scope)
);
$templateConfig.variables['APPWRITE_API_KEY'] = key.secret;
const key = await sdk.forConsole.projects.createKey(
$page.params.project,
'Generated for Template',
scopes.map((scope) => scope.scope)
);
$templateConfig.variables['APPWRITE_API_KEY'] = key.secret;
const response = await sdk.forProject.functions.create(
$templateConfig.$id || ID.unique(),
$templateConfig.name,
$templateConfig.runtime,
runtimeDetail.entrypoint,
$template.permissions || undefined,
$template.events || undefined,
$template.cron || undefined,
$template.timeout || undefined,
undefined,
undefined,
runtimeDetail.commands || undefined,
$installation.$id,
$repository.id,
$choices.branch,
$choices.silentMode || undefined,
$choices.rootDir || undefined,
$template.providerRepositoryId,
$template.providerOwner,
runtimeDetail.providerRootDirectory,
$template.providerBranch
);
goto(`${base}/console/project-${$page.params.project}/functions/function-${response.$id}`);
addNotification({
message: `${response.name} has been created`,
type: 'success'
});
trackEvent(Submit.FunctionCreate, {
customId: !!response.$id
});
resetState();
wizard.hide();
const response = await sdk.forProject.functions.create(
$templateConfig.$id || ID.unique(),
$templateConfig.name,
$templateConfig.runtime,
runtimeDetail.entrypoint,
$template.permissions || undefined,
$template.events || undefined,
$template.cron || undefined,
$template.timeout || undefined,
undefined,
undefined,
runtimeDetail.commands || undefined,
$installation.$id,
$repository.id,
$choices.branch,
$choices.silentMode || undefined,
$choices.rootDir || undefined,
$template.providerRepositoryId,
$template.providerOwner,
runtimeDetail.providerRootDirectory,
$template.providerBranch
);
goto(
`${base}/console/project-${$page.params.project}/functions/function-${response.$id}`
);
addNotification({
message: `${response.name} has been created`,
type: 'success'
});
trackEvent(Submit.FunctionCreate, {
customId: !!response.$id
});
resetState();
} catch (error) {
addNotification({
message: error.message,
type: 'error'
});
trackError(error, Submit.FunctionCreate);
}
}
function resetState() {
wizard.hide();
templateConfig.set(null);
@@ -50,7 +50,7 @@
placeholder={variable.placeholder ?? 'Enter value'}
required={variable.required}
autocomplete={false}
bind:value={$templateConfig.appwriteApiKey} />
bind:value={$templateConfig.variables[variable.name]} />
<Helper type="neutral">
{@html variable.description}
@@ -109,7 +109,7 @@
placeholder={variable.placeholder ?? 'Enter value'}
required={variable.required}
autocomplete={false}
bind:value={$templateConfig.appwriteApiKey} />
bind:value={$templateConfig.variables[variable.name]} />
<Helper type="neutral">
{@html variable.description}
@@ -168,11 +168,24 @@
</svelte:fragment>
</CardGrid>
{:else}
<Empty
single
href="https://appwrite.io/docs/functions#createFunction"
target="deployment"
on:click />
<Empty single target="deployment">
<div class="u-text-center">
<Heading size="7" tag="h2"
>Create your first deployment to get started.</Heading>
<p class="body-text-2 u-bold u-margin-block-start-4">
Learn more about deployments in our Documentation.
</p>
</div>
<div class="u-flex u-gap-16 u-main-center">
<Button
external
href="https://appwrite.io/docs/functions#createFunction"
text
event="empty_documentation"
ariaLabel={`create {target}`}>Documentation</Button>
<Create secondary />
</div>
</Empty>
{/if}
<div class="common-section">
@@ -202,19 +215,7 @@
warning={status === 'pending'}
success={status === 'completed' || status === 'ready'}
info={status === 'processing' || status === 'building'}>
{#if deployment.$id === $func.deployment}
<span
class="text u-trim"
use:tooltip={{
content: 'Active Deployment',
placement: 'top'
}}>
<span class="icon-check-circle" aria-hidden="true" />
<span>{status}</span>
</span>
{:else}
<span>{status}</span>
{/if}
{status}
</Pill>
</TableCell>
<TableCellText width={70} title="Source">
@@ -306,13 +307,12 @@
text
event="empty_documentation"
ariaLabel={`create {target}`}>Documentation</Button>
<Button secondary on:click>Create deployment</Button>
<Create />
</div>
</Empty>
{/if}
{:else}
<Empty single target="deployment" on:click>
<Empty single target="deployment">
<div class="u-text-center">
<Heading size="7" tag="h2">Create your first deployment to get started.</Heading>
<p class="body-text-2 u-bold u-margin-block-start-4">
@@ -8,8 +8,8 @@
</script>
{#if deployment.type === 'vcs'}
<span
class="u-underline u-cursor-pointer"
<button
class=" u-cursor-pointer"
use:tooltip={{
interactive: true,
allowHTML: true,
@@ -19,7 +19,7 @@
instance.setContent(tooltipContent);
});
}
}}><span class="icon-github" aria-hidden="true" /> Git</span>
}}><span class="icon-github" aria-hidden="true" /> <span class="link">Git</span></button>
{:else if deployment.type === 'manual'}
<span class="icon-code" aria-hidden="true" /> <span>Manual</span>
{/if}