Update to use new sizes instead of individual memory cpu specs

This commit is contained in:
Bradley Schofield committed 2024-07-16 14:25:44 +09:00
1 parent 2af612f030
commit c60e6d2bc8
5 files changed
+38 -64

No files matched your search

+15 -17
View File
@@ -129,24 +129,27 @@ export type Func = {
*/
providerSilentMode: boolean;
/**
* CPU limit
* Runtime Size
*/
cpus: number;
/**
* Memory limit
*/
memory: number;
size: string;
};
export class SpecsFunctions {
export type Sizes = {
/**
* List of available runtime sizes
*/
sizes: string[];
};
export class SizesFunctions {
client: Client;
constructor(client: Client) {
this.client = client;
}
async getSpecs(): Promise<Specs> {
const path = '/functions/specs';
async getSizes(): Promise<Sizes> {
const path = '/functions/sizes';
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call('GET', uri, {
@@ -197,8 +200,7 @@ export class SpecsFunctions {
providerBranch?: string,
providerSilentMode?: boolean,
providerRootDirectory?: string,
cpus?: number,
memory?: number
size?: string
): Promise<Func> {
if (typeof functionId === 'undefined') {
throw new AppwriteException('Missing required parameter: "functionId"');
@@ -271,12 +273,8 @@ export class SpecsFunctions {
payload['providerRootDirectory'] = providerRootDirectory;
}
if (typeof cpus !== 'undefined') {
payload['cpus'] = cpus;
}
if (typeof memory !== 'undefined') {
payload['memory'] = memory;
if (typeof size !== 'undefined') {
payload['size'] = size;
}
const uri = new URL(this.client.config.endpoint + apiPath);
+2 -2
View File
@@ -23,7 +23,7 @@ import {
} from '@appwrite.io/console';
import { Billing } from '../sdk/billing';
import { Sources } from '$lib/sdk/sources';
import { SpecsFunctions } from '$lib/sdk/functionsSpec';
import { SizesFunctions } from '$lib/sdk/functionsSpec';
const endpoint = VARS.APPWRITE_ENDPOINT ?? `${globalThis?.location?.origin}/v1`;
@@ -39,7 +39,7 @@ const sdkForProject = {
avatars: new Avatars(clientProject),
databases: new Databases(clientProject),
functions: new Functions(clientProject),
specsFunctions: new SpecsFunctions(clientProject),
sizesFunctions: new SizesFunctions(clientProject),
health: new Health(clientProject),
locale: new Locale(clientProject),
messaging: new Messaging(clientProject),
@@ -8,10 +8,10 @@ import type { LayoutLoad } from './$types';
export const load: LayoutLoad = async ({ depends }) => {
depends(Dependencies.FUNCTION_INSTALLATIONS);
const [runtimesList, installations, specs] = await Promise.all([
const [runtimesList, installations, sizes] = await Promise.all([
sdk.forProject.functions.listRuntimes(),
sdk.forProject.vcs.listInstallations([Query.limit(100)]),
sdk.forProject.specsFunctions.getSpecs()
sdk.forProject.sizesFunctions.getSizes()
]);
return {
@@ -19,6 +19,6 @@ export const load: LayoutLoad = async ({ depends }) => {
breadcrumbs: Breadcrumbs,
runtimesList,
installations,
specs
sizes
};
};
@@ -10,46 +10,32 @@
import { onMount } from 'svelte';
import { func } from '../store';
import InputSelect from '$lib/elements/forms/inputSelect.svelte';
import { runtimesList, specs } from '../../store';
import { runtimesList, sizes } from '../../store';
import { isValueOfStringEnum } from '$lib/helpers/types';
import { Runtime } from '@appwrite.io/console';
const functionId = $page.params.function;
let runtime: string = null;
let memory: number = null;
let cpus: number = null;
let size: string = null;
let options = [];
let cpuOptions = [];
let memoryOptions = [];
let sizeOptions = [];
onMount(async () => {
runtime ??= $func.runtime;
memory ??= $func.memory;
cpus ??= $func.cpus;
size ??= $func.size
let runtimes = await $runtimesList;
let allowedSpecs = await $specs;
let allowedSizes = await $sizes;
options = runtimes.runtimes.map((runtime) => ({
label: `${runtime.name} - ${runtime.version}`,
value: runtime.$id
}));
memoryOptions = allowedSpecs.memory.map((memory) =>
memory > 1024
? {
label: `${memory / 1024} GB`,
value: memory
}
: {
label: `${memory} MB`,
value: memory
}
);
cpuOptions = allowedSpecs.cpus.map((cpu) => ({
label: cpu === 1 ? `${cpu} CPU Cores` : `${cpu} CPU Core`,
value: cpu
console.log(allowedSizes);
sizeOptions = allowedSizes.map((size) => ({
label: size,
value: size
}));
});
@@ -58,7 +44,7 @@
if (!isValueOfStringEnum(Runtime, runtime)) {
throw new Error(`Invalid runtime: ${runtime}`);
}
await sdk.forProject.specsFunctions.update(
await sdk.forProject.sizesFunctions.update(
functionId,
$func.name,
runtime,
@@ -75,8 +61,7 @@
$func.providerBranch || undefined,
$func.providerSilentMode || undefined,
$func.providerRootDirectory || undefined,
cpus,
memory
size
);
await invalidate(Dependencies.FUNCTION);
addNotification({
@@ -94,7 +79,7 @@
}
$: isUpdateButtonEnabled =
runtime !== $func?.runtime || memory !== $func?.memory || cpus !== $func?.cpus;
runtime !== $func?.runtime || size !== $func?.size;
</script>
<Form onSubmit={updateRuntime}>
@@ -112,19 +97,11 @@
required
hideRequired />
<InputSelect
label="Memory Limit"
id="memory"
placeholder="Select memory"
bind:value={memory}
options={memoryOptions}
required
hideRequired />
<InputSelect
label="CPU Limit"
id="cpus"
placeholder="Select cpu cores"
bind:value={cpus}
options={cpuOptions}
label="Machine Size"
id="size"
placeholder="Select runtime size"
bind:value={size}
options={sizeOptions}
required
hideRequired />
</FormList>
@@ -1,14 +1,13 @@
import { page } from '$app/stores';
import { derived } from 'svelte/store';
import type { Models } from '@appwrite.io/console';
import type { Specs } from '$lib/sdk/functionsSpec';
export const runtimesList = derived(
page,
async ($page) => (await $page.data.runtimesList) as Models.RuntimeList
);
export const specs = derived(page, async ($page) => (await $page.data.specs) as Specs);
export const sizes = derived(page, async ($page) => (await $page.data.sizes.sizes) as string[]);
export const baseRuntimesList = derived(runtimesList, async ($runtimesList) => {
const baseRuntimes = new Map<string, Models.Runtime>();