-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathupdateResourceLimits.svelte
More file actions
151 lines (142 loc) · 6.57 KB
/
Copy pathupdateResourceLimits.svelte
File metadata and controls
151 lines (142 loc) · 6.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<script lang="ts">
import { invalidate } from '$app/navigation';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { CardGrid } from '$lib/components';
import { Dependencies } from '$lib/constants';
import { Button, Form, InputSelect } from '$lib/elements/forms';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { Adapter, BuildRuntime, Framework, type Models } from '@appwrite.io/console';
import Link from '$lib/elements/link.svelte';
import { Alert, Icon, Tooltip } from '@appwrite.io/pink-svelte';
import { IconInfo } from '@appwrite.io/pink-icons-svelte';
import { getChangePlanUrl, isStarterPlan } from '$lib/stores/billing';
import { isCloud } from '$lib/system';
import { organization } from '$lib/stores/organization';
import { page } from '$app/state';
export let site: Models.Site;
export let buildSpecs: Models.SpecificationList;
export let runtimeSpecs: Models.SpecificationList;
let buildSpecification = site.buildSpecification;
let runtimeSpecification = site.runtimeSpecification;
let originalBuild = site.buildSpecification;
let originalRuntime = site.runtimeSpecification;
let siteId: string | undefined = undefined;
$: if (site.$id !== siteId) {
siteId = site.$id;
buildSpecification = site.buildSpecification;
runtimeSpecification = site.runtimeSpecification;
}
$: {
originalBuild = site.buildSpecification;
originalRuntime = site.runtimeSpecification;
}
async function updateResourceLimits() {
try {
await sdk.forProject(page.params.region, page.params.project).sites.update({
siteId: site.$id,
name: site.name,
framework: site.framework as Framework,
enabled: site?.enabled ?? undefined,
logging: site?.logging ?? undefined,
timeout: site?.timeout || undefined,
installCommand: site?.installCommand || undefined,
buildCommand: site?.buildCommand || undefined,
startCommand: site?.startCommand || undefined,
outputDirectory: site?.outputDirectory || undefined,
buildRuntime: (site?.buildRuntime as BuildRuntime) || undefined,
adapter: site?.adapter as Adapter,
fallbackFile: site?.fallbackFile || undefined,
installationId: site?.installationId || undefined,
providerRepositoryId: site?.providerRepositoryId || undefined,
providerBranch: site?.providerBranch || undefined,
providerSilentMode: site?.providerSilentMode ?? undefined,
providerRootDirectory: site?.providerRootDirectory || undefined,
buildSpecification: buildSpecification || undefined,
runtimeSpecification: runtimeSpecification || undefined,
deploymentRetention: site?.deploymentRetention ?? undefined
});
await invalidate(Dependencies.SITE);
addNotification({
type: 'success',
message: 'Resource limits have been updated'
});
trackEvent(Submit.SiteUpdateResourceLimits);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.SiteUpdateResourceLimits);
}
}
const buildEnabledSpecs = buildSpecs.specifications.filter((spec) => spec.enabled);
const runtimeEnabledSpecs = runtimeSpecs.specifications.filter((spec) => spec.enabled);
const buildOptions = buildSpecs.specifications.map((spec) => ({
label: `${spec.cpus} CPU, ${spec.memory} MB RAM`,
value: spec.slug,
disabled: !spec.enabled
}));
const runtimeOptions = runtimeSpecs.specifications.map((spec) => ({
label: `${spec.cpus} CPU, ${spec.memory} MB RAM`,
value: spec.slug,
disabled: !spec.enabled
}));
</script>
<Form onSubmit={updateResourceLimits}>
<CardGrid>
<svelte:fragment slot="title">Resource limits</svelte:fragment>
Define your site's compute specifications, including CPU and memory, to optimize performance for
your workloads. <Link href="https://appwrite.io/docs/advanced/platform/compute" external>
Learn more
</Link>.
<svelte:fragment slot="aside">
<InputSelect
label="Build specification"
id="build-specification"
required
disabled={buildEnabledSpecs.length < 1}
bind:value={buildSpecification}
options={buildOptions}>
<Tooltip slot="info">
<Icon icon={IconInfo} size="s" />
<span slot="tooltip">
CPU and memory used when installing dependencies and building your site for
deployment.
</span>
</Tooltip>
</InputSelect>
<InputSelect
label="Runtime specification"
id="runtime-specification"
required
disabled={runtimeEnabledSpecs.length < 1}
bind:value={runtimeSpecification}
options={runtimeOptions}>
<Tooltip slot="info">
<Icon icon={IconInfo} size="s" />
<span slot="tooltip">
CPU and memory used when your site serves traffic, including server-side
rendering (SSR).
</span>
</Tooltip>
</InputSelect>
<!-- always show upgrade on starters -->
{@const isStarter = isStarterPlan($organization.billingPlanId)}
{#if isCloud && isStarter}
<Alert.Inline title="Customizing specs available with Pro or Scale plans">
Upgrade your plan to adjust your CPU and RAM beyond the default.
<svelte:fragment slot="actions">
<Button href={getChangePlanUrl($organization.$id)} compact>Upgrade</Button>
</svelte:fragment>
</Alert.Inline>
{/if}
</svelte:fragment>
<svelte:fragment slot="actions">
<Button
disabled={originalBuild === buildSpecification &&
originalRuntime === runtimeSpecification}
submit>Update</Button>
</svelte:fragment>
</CardGrid>
</Form>