From 7624a7fc77e880b3fd62c0d58de5a0c6f93e70d8 Mon Sep 17 00:00:00 2001 From: alexweininger Date: Sun, 30 May 2021 22:22:01 -0500 Subject: [PATCH] function tag creation --- src/appwrite/Functions.ts | 8 +-- src/commands/common/editValue.ts | 2 +- src/commands/functions/createExecution.ts | 52 +++++++++++++++++-- src/commands/functions/createTag.ts | 48 ++++++++++++----- src/commands/functions/viewExecutionErrors.ts | 11 ++-- src/commands/functions/viewExecutionOutput.ts | 12 +++-- src/extensionVariables.ts | 2 +- .../{ => editable}/EditableTreeItemBase.ts | 0 .../{ => editable}/EnumEditableTreeItem.ts | 0 .../{ => editable}/SimpleEditableTreeItem.ts | 0 .../{ => editable}/StringEditableTreeItem.ts | 0 src/tree/database/CollectionTreeItem.ts | 4 +- src/tree/database/DatabaseTreeItemProvider.ts | 6 +-- src/tree/database/DocumentsTreeItem.ts | 4 +- .../database/settings/PermissionsTreeItem.ts | 4 +- src/tree/database/settings/RulesTreeItem.ts | 4 +- src/tree/functions/FunctionTreeItem.ts | 4 +- .../functions/FunctionsTreeItemProvider.ts | 9 ++-- .../functions/executions/ExecutionTreeItem.ts | 22 ++++---- .../executions/ExecutionsTreeItem.ts | 11 ++-- src/tree/functions/settings/EventsTreeItem.ts | 2 +- .../settings/FunctionSettingsTreeItem.ts | 4 +- src/tree/functions/settings/NameTreeItem.ts | 2 +- .../functions/settings/ScheduleTreeItem.ts | 2 +- .../functions/settings/TimeoutTreeItem.ts | 2 +- src/tree/functions/settings/VarTreeItem.ts | 2 +- src/tree/functions/settings/VarsTreeItem.ts | 4 +- src/tree/functions/tags/TagsTreeItem.ts | 5 +- src/utils/date.ts | 8 ++- src/utils/sleep.ts | 5 ++ src/utils/tar.ts | 9 ++-- src/utils/types.d.ts | 6 +++ 32 files changed, 180 insertions(+), 74 deletions(-) rename src/tree/common/{ => editable}/EditableTreeItemBase.ts (100%) rename src/tree/common/{ => editable}/EnumEditableTreeItem.ts (100%) rename src/tree/common/{ => editable}/SimpleEditableTreeItem.ts (100%) rename src/tree/common/{ => editable}/StringEditableTreeItem.ts (100%) create mode 100644 src/utils/sleep.ts create mode 100644 src/utils/types.d.ts diff --git a/src/appwrite/Functions.ts b/src/appwrite/Functions.ts index 2fb0e6a..892b69e 100644 --- a/src/appwrite/Functions.ts +++ b/src/appwrite/Functions.ts @@ -1,10 +1,10 @@ -import { Client, Execution, ExecutionList, FunctionsClient, TagList, Vars } from "../appwrite"; +import { Client, Execution, ExecutionList, FunctionsClient, Tag, TagList, Vars } from "../appwrite"; import { AppwriteSDK } from '../constants'; import AppwriteCall from '../utils/AppwriteCall'; import { ReadStream } from 'node:fs'; export class Functions { - private readonly functions: FunctionsClient; + public readonly functions: FunctionsClient; constructor(client: Client) { this.functions = new AppwriteSDK.Functions(client); @@ -28,7 +28,7 @@ export class Functions { public async delete(functionId: string): Promise { return await AppwriteCall(this.functions.delete(functionId)); } - public async createTag(functionId: string, command: string, code: ReadStream): Promise { + public async createTag(functionId: string, command: string, code: ReadStream): Promise { return await AppwriteCall(this.functions.createTag(functionId, command, code)); } public async listTags(id: string, search?: string, limit?: number, offset?: number, orderType?: 'ASC' | 'DESC'): Promise { @@ -40,7 +40,7 @@ export class Functions { public async deleteTag(functionId: string, tagId: string): Promise { return await AppwriteCall(this.functions.deleteTag(functionId, tagId)); } - public async createExecution(functionId: string, data?: string): Promise { + public async createExecution(functionId: string, data?: string): Promise { return await AppwriteCall(this.functions.createExecution(functionId, data)); } public async listExecutions(functionId: string, search?: string, limit?: number, offset?: number, orderType?: 'ASC' | 'DESC'): Promise { diff --git a/src/commands/common/editValue.ts b/src/commands/common/editValue.ts index 92a101f..d7396f8 100644 --- a/src/commands/common/editValue.ts +++ b/src/commands/common/editValue.ts @@ -1,4 +1,4 @@ -import { EditableTreeItem } from '../../tree/common/SimpleEditableTreeItem'; +import { EditableTreeItem } from '../../tree/common/editable/SimpleEditableTreeItem'; export async function editValue(treeItem: EditableTreeItem): Promise { if (treeItem === undefined) { diff --git a/src/commands/functions/createExecution.ts b/src/commands/functions/createExecution.ts index 3c246da..a372c7f 100644 --- a/src/commands/functions/createExecution.ts +++ b/src/commands/functions/createExecution.ts @@ -1,10 +1,56 @@ +import { window } from 'vscode'; +import { Execution } from '../../appwrite'; import { functionsClient } from '../../client'; import { ext } from '../../extensionVariables'; import { FunctionTreeItem } from '../../tree/functions/FunctionTreeItem'; +import { sleep } from '../../utils/sleep'; +import { viewExecutionErrors } from './viewExecutionErrors'; +import { viewExecutionOutput } from './viewExecutionOutput'; export async function createExecution(functionTreeItem: FunctionTreeItem): Promise { const func = functionTreeItem.func; - ext.outputChannel.appendLog(`Creating execution for function ${func.name}`); - - await functionsClient?.createExecution(func.$id); + await executeFunction(func.$id); +} + +export async function executeFunction(functionId: string): Promise { + ext.outputChannel.appendLog(`Creating execution for function with ID: ${functionId}`); + let execution = await functionsClient?.createExecution(functionId); + await ext.tree?.functions?.refresh(); + + if (execution === undefined) { + return; + } + + execution = await waitForExecution(execution); + + if (execution === undefined) { + return; + } + + const failed = execution.status === "failed"; + const item = !failed ? "View output" : "View errors"; + const action = await window.showInformationMessage(`Execution ${failed ? "failed" : "completed"} in ${execution.time.toFixed(2)}s.`, item); + if (action === item) { + if (item === "View output") { + await viewExecutionOutput(execution); + return; + } + await viewExecutionErrors(execution); + return; + } +} + +async function waitForExecution(execution: Execution | undefined): Promise { + ext.outputChannel.appendLog("Waiting for execution..."); + if (execution === undefined) { + return; + } + if (execution.status === "processing" || execution.status === "waiting") { + await sleep(2000); + + ext.outputChannel.appendLog("Execution still ..."); + return await waitForExecution(await functionsClient?.getExecution(execution.functionId, execution.$id)); + } + + return execution; } diff --git a/src/commands/functions/createTag.ts b/src/commands/functions/createTag.ts index e00c829..7f32684 100644 --- a/src/commands/functions/createTag.ts +++ b/src/commands/functions/createTag.ts @@ -1,40 +1,64 @@ -import { ProgressLocation, Uri, window } from "vscode"; -import { functionsClient, storageClient } from "../../client"; +import { ProgressLocation, Uri, window, workspace } from "vscode"; +import { functionsClient } from "../../client"; import { getTarReadStream } from "../../utils/tar"; import { ext } from "../../extensionVariables"; import * as fs from "fs"; import { TagsTreeItem } from "../../tree/functions/tags/TagsTreeItem"; import { selectWorkspaceFolder } from "../../utils/workspace"; +import { ProgressMessage } from '../../utils/types'; +import { Tag } from '../../appwrite'; + export async function createTag(item: TagsTreeItem | Uri): Promise { if (item instanceof Uri) { - window.withProgress({ location: ProgressLocation.Notification, title: "Creating tag..." }, async (_progress, _token) => { - await createTagFromUri(item); + const tag = await window.withProgress({ location: ProgressLocation.Notification, title: "Creating tag..." }, async (progress, _token) => { + return await createTagFromUri(item, progress); }); + if (tag) { + await window.showInformationMessage(`Successfully created tag with size ${tag.size}B.`, "Execution function", "View in console"); + return; + } return; } if (item instanceof TagsTreeItem) { const folder = await selectWorkspaceFolder("Select folder of your function code."); console.log(folder); - window.withProgress({ location: ProgressLocation.Notification, title: "Creating tag..." }, async (_progress, _token) => { - await createTagFromUri(Uri.parse(folder)); + const tag = await window.withProgress({ location: ProgressLocation.Notification, title: "Creating tag..." }, async (progress, _token) => { + return await createTagFromUri(Uri.parse(folder), progress); }); + + if (tag) { + await window.showInformationMessage(`Successfully created tag with size ${tag.size}B.`); + return; + } } } -async function createTagFromUri(uri: Uri): Promise { - const tarFilePath = await getTarReadStream(uri); +async function createTagFromUri(uri: Uri, progress: ProgressMessage): Promise { + + progress.report({message: "Creating tarball", increment: 10}); + if (functionsClient === undefined) { return; } - if (tarFilePath === undefined) { - ext.outputChannel.appendLog("Error creating tar file."); + let tarFilePath; + try { + tarFilePath = await getTarReadStream(uri); + } catch (e) { + window.showErrorMessage("Error creating tar file.\n" + e); return; } + if (tarFilePath === undefined) { + window.showErrorMessage("Failed to create tar file."); + ext.outputChannel.appendLog("Failed to create tar file."); + return; + } + // somehow makes the upload work + await workspace.fs.readFile(Uri.file(tarFilePath)); + progress.report({message: "Uploading tag", increment: 60}); try { - await functionsClient.createTag("60b1836a8e5d9", "python ./hello.py", fs.createReadStream(tarFilePath)); - await storageClient?.createFile(fs.createReadStream(tarFilePath)); + return await functionsClient.createTag("60b1836a8e5d9", "python ./hello.py", fs.createReadStream(tarFilePath)); } catch (e) { ext.outputChannel.appendLog("Creating tag error: " + e); } diff --git a/src/commands/functions/viewExecutionErrors.ts b/src/commands/functions/viewExecutionErrors.ts index 3d5c154..2a79f28 100644 --- a/src/commands/functions/viewExecutionErrors.ts +++ b/src/commands/functions/viewExecutionErrors.ts @@ -1,11 +1,16 @@ +import { Execution } from '../../appwrite'; import { ExecutionTreeItem } from "../../tree/functions/executions/ExecutionTreeItem"; import { openReadOnlyContent } from "../../ui/openReadonlyContent"; -export async function viewExecutionErrors(executionItem: ExecutionTreeItem): Promise { +export async function viewExecutionErrors(executionItem: ExecutionTreeItem | Execution): Promise { if (executionItem === undefined) { return; } - const execution = executionItem.execution; - await openReadOnlyContent({ label: `${executionItem.parent.parent.func.name} execution stderr`, fullId: `${execution.$id}-errors.txt` }, execution.stderr, '.txt'); + let execution = executionItem as Execution; + + if (executionItem instanceof ExecutionTreeItem) { + execution = executionItem.execution; + } + await openReadOnlyContent({ label: `Execution stderr`, fullId: `${execution.$id}-errors.txt` }, execution.stderr, '.txt'); } diff --git a/src/commands/functions/viewExecutionOutput.ts b/src/commands/functions/viewExecutionOutput.ts index 94e1415..dde8325 100644 --- a/src/commands/functions/viewExecutionOutput.ts +++ b/src/commands/functions/viewExecutionOutput.ts @@ -1,11 +1,17 @@ +import { Execution } from '../../appwrite'; import { ExecutionTreeItem } from "../../tree/functions/executions/ExecutionTreeItem"; import { openReadOnlyContent } from "../../ui/openReadonlyContent"; -export async function viewExecutionOutput(executionItem: ExecutionTreeItem): Promise { +export async function viewExecutionOutput(executionItem: ExecutionTreeItem | Execution): Promise { if (executionItem === undefined) { return; } - const execution = executionItem.execution; - await openReadOnlyContent({ label: `${executionItem.parent.parent.func.name} execution stdout`, fullId: `${execution.$id}-output.txt` }, execution.stdout, '.txt'); + let execution = executionItem as Execution; + + if (executionItem instanceof ExecutionTreeItem) { + execution = executionItem.execution; + } + + await openReadOnlyContent({ label: `Execution stdout`, fullId: `${execution.$id}-output.txt` }, execution.stdout, '.txt'); } diff --git a/src/extensionVariables.ts b/src/extensionVariables.ts index b6681ad..bacaaf7 100644 --- a/src/extensionVariables.ts +++ b/src/extensionVariables.ts @@ -17,7 +17,7 @@ export type AppwriteTree = { }; export type Ext = { - context?: ExtensionContext; + context: ExtensionContext; outputChannel: AppwriteOutputChannel; tree?: AppwriteTree; }; diff --git a/src/tree/common/EditableTreeItemBase.ts b/src/tree/common/editable/EditableTreeItemBase.ts similarity index 100% rename from src/tree/common/EditableTreeItemBase.ts rename to src/tree/common/editable/EditableTreeItemBase.ts diff --git a/src/tree/common/EnumEditableTreeItem.ts b/src/tree/common/editable/EnumEditableTreeItem.ts similarity index 100% rename from src/tree/common/EnumEditableTreeItem.ts rename to src/tree/common/editable/EnumEditableTreeItem.ts diff --git a/src/tree/common/SimpleEditableTreeItem.ts b/src/tree/common/editable/SimpleEditableTreeItem.ts similarity index 100% rename from src/tree/common/SimpleEditableTreeItem.ts rename to src/tree/common/editable/SimpleEditableTreeItem.ts diff --git a/src/tree/common/StringEditableTreeItem.ts b/src/tree/common/editable/StringEditableTreeItem.ts similarity index 100% rename from src/tree/common/StringEditableTreeItem.ts rename to src/tree/common/editable/StringEditableTreeItem.ts diff --git a/src/tree/database/CollectionTreeItem.ts b/src/tree/database/CollectionTreeItem.ts index 22c3a02..79ea8c4 100644 --- a/src/tree/database/CollectionTreeItem.ts +++ b/src/tree/database/CollectionTreeItem.ts @@ -1,13 +1,13 @@ import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode"; import { Collection } from "../../appwrite"; import { databaseClient } from "../../client"; -import { AppwriteTreeItemBase } from "../../ui/AppwriteTreeItemBase"; +import { AwTreeItem } from "../common/AwTreeItem"; import { DatabaseTreeItemProvider } from "./DatabaseTreeItemProvider"; import { DocumentsTreeItem } from "./DocumentsTreeItem"; import { PermissionsTreeItem } from "./settings/PermissionsTreeItem"; import { RulesTreeItem } from "./settings/RulesTreeItem"; -export class CollectionTreeItem extends AppwriteTreeItemBase { +export class CollectionTreeItem extends AwTreeItem { constructor(public collection: Collection, public readonly provider: DatabaseTreeItemProvider) { super(undefined, collection.name); } diff --git a/src/tree/database/DatabaseTreeItemProvider.ts b/src/tree/database/DatabaseTreeItemProvider.ts index d5a9b26..17211c3 100644 --- a/src/tree/database/DatabaseTreeItemProvider.ts +++ b/src/tree/database/DatabaseTreeItemProvider.ts @@ -4,8 +4,8 @@ import AppwriteCall from "../../utils/AppwriteCall"; import { Collection, CollectionsList } from "../../appwrite"; import { CollectionTreeItem } from "./CollectionTreeItem"; import { AppwriteSDK } from "../../constants"; -import { AppwriteTreeItemBase } from "../../ui/AppwriteTreeItemBase"; import { ext } from '../../extensionVariables'; +import { AwParentTreeItem } from '../common/AwParentTreeItem'; export class DatabaseTreeItemProvider implements vscode.TreeDataProvider { private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter< @@ -33,8 +33,8 @@ export class DatabaseTreeItemProvider implements vscode.TreeDataProvider { +export class DocumentsTreeItem extends AwTreeItem { constructor(parent: CollectionTreeItem) { super(parent, "Documents"); } diff --git a/src/tree/database/settings/PermissionsTreeItem.ts b/src/tree/database/settings/PermissionsTreeItem.ts index 64788fd..bf43212 100644 --- a/src/tree/database/settings/PermissionsTreeItem.ts +++ b/src/tree/database/settings/PermissionsTreeItem.ts @@ -1,11 +1,11 @@ import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode"; import { Permissions } from "../../../appwrite"; -import { AppwriteTreeItemBase } from "../../../ui/AppwriteTreeItemBase"; +import { AwTreeItem } from "../../common/AwTreeItem"; import { CollapsableTreeItem } from "../../CollapsableTreeItem"; import { CollectionTreeItem } from "../CollectionTreeItem"; import { PermissionTreeItem } from "./PermissionTreeItem"; -export class PermissionsTreeItem extends AppwriteTreeItemBase { +export class PermissionsTreeItem extends AwTreeItem { public readonly permissions: Permissions; constructor(parent: CollectionTreeItem) { diff --git a/src/tree/database/settings/RulesTreeItem.ts b/src/tree/database/settings/RulesTreeItem.ts index d4722e7..4159865 100644 --- a/src/tree/database/settings/RulesTreeItem.ts +++ b/src/tree/database/settings/RulesTreeItem.ts @@ -1,11 +1,11 @@ import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode"; import { Rule } from "../../../appwrite"; -import { AppwriteTreeItemBase } from "../../../ui/AppwriteTreeItemBase"; +import { AwTreeItem } from "../../common/AwTreeItem"; import { CommandTreeItem } from "../../CommandTreeItem"; import { CollectionTreeItem } from "../CollectionTreeItem"; import { RuleTreeItem } from "./RuleTreeItem"; -export class RulesTreeItem extends AppwriteTreeItemBase { +export class RulesTreeItem extends AwTreeItem { public readonly rules: Rule[]; constructor(parent: CollectionTreeItem) { diff --git a/src/tree/functions/FunctionTreeItem.ts b/src/tree/functions/FunctionTreeItem.ts index ae5e1ed..4a7d459 100644 --- a/src/tree/functions/FunctionTreeItem.ts +++ b/src/tree/functions/FunctionTreeItem.ts @@ -1,13 +1,13 @@ import { MarkdownString, ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode"; import { Function } from "../../appwrite"; -import { AppwriteTreeItemBase } from "../../ui/AppwriteTreeItemBase"; +import { AwTreeItem } from "../common/AwTreeItem"; import { msToDate } from '../../utils/date'; import { ExecutionsTreeItem } from './executions/ExecutionsTreeItem'; import { FunctionsTreeItemProvider } from './FunctionsTreeItemProvider'; import { FunctionSettingsTreeItem } from './settings/FunctionSettingsTreeItem'; import { TagsTreeItem } from './tags/TagsTreeItem'; -export class FunctionTreeItem extends AppwriteTreeItemBase { +export class FunctionTreeItem extends AwTreeItem { constructor(public func: Function, public readonly provider: FunctionsTreeItemProvider) { super(undefined, func.name); this.tooltip = new MarkdownString(`ID: ${func.$id} \nLast updated: ${msToDate(func.dateUpdated)} \nCreated: ${msToDate(func.dateCreated)}`); diff --git a/src/tree/functions/FunctionsTreeItemProvider.ts b/src/tree/functions/FunctionsTreeItemProvider.ts index 8b9b719..267d004 100644 --- a/src/tree/functions/FunctionsTreeItemProvider.ts +++ b/src/tree/functions/FunctionsTreeItemProvider.ts @@ -2,10 +2,11 @@ import * as vscode from "vscode"; import { client } from "../../client"; import { Function, FunctionsList } from "../../appwrite"; import { AppwriteSDK } from "../../constants"; -import { AppwriteTreeItemBase } from "../../ui/AppwriteTreeItemBase"; +import { AwTreeItem } from "../common/AwTreeItem"; import { ext } from "../../extensionVariables"; import { EventEmitter, TreeItem } from "vscode"; import { FunctionTreeItem } from "./FunctionTreeItem"; +import { AwParentTreeItem } from '../common/AwParentTreeItem'; export class FunctionsTreeItemProvider implements vscode.TreeDataProvider { private _onDidChangeTreeData: EventEmitter = new EventEmitter(); @@ -25,7 +26,7 @@ export class FunctionsTreeItemProvider implements vscode.TreeDataProvider { + async getChildren(parent?: AwTreeItem | TreeItem): Promise { if (client === undefined) { return Promise.resolve([]); } @@ -43,8 +44,8 @@ export class FunctionsTreeItemProvider implements vscode.TreeDataProvider = { @@ -12,17 +13,11 @@ const executionStatusIcons: Record = { failed: new ThemeIcon("circle-filled", new ThemeColor("testing.iconFailed")), }; -function sleep(ms: number) { - return new Promise((resolve) => { - setTimeout(resolve, ms); - }); -} - export class ExecutionTreeItem extends TreeItem { public isAutoRefreshing: boolean = false; private refreshCount: number = 0; - constructor(public readonly parent: ExecutionsTreeItem, public readonly execution: Execution) { + constructor(public readonly parent: ExecutionsTreeItem, public execution: Execution) { super(execution.$id); this.label = this.getLabel(execution); this.iconPath = executionStatusIcons[execution.status]; @@ -31,7 +26,9 @@ export class ExecutionTreeItem extends TreeItem { this.description = execution.trigger; this.contextValue = this.getContextValue(execution); this.isAutoRefreshing = execution.status === "processing" || execution.status === "waiting"; - this.autoRefresh(); + if (this.isAutoRefreshing) { + this.autoRefresh(); + } } async autoRefresh(): Promise { @@ -47,12 +44,11 @@ export class ExecutionTreeItem extends TreeItem { this.isAutoRefreshing = false; return; } - + this.execution = execution; this.contextValue = this.getContextValue(execution); this.iconPath = executionStatusIcons[execution.status]; this.label = this.getLabel(execution); this.isAutoRefreshing = execution.status === "processing" || execution.status === "waiting"; - ext.tree?.functions?.refreshChild(this); await sleep(1000); this.autoRefresh(); @@ -60,11 +56,15 @@ export class ExecutionTreeItem extends TreeItem { getLabel(execution: Execution): string { if (execution.status === "completed" || execution.status === "failed") { - return `${this.getCreated(execution)} (${execution.time.toPrecision(2)}s)`; + return `${this.getCreated(execution)} (${this.getExecutionTime(execution)}s)`; } return `${this.getCreated(execution)} (${execution.status})`; } + getExecutionTime(execution: Execution): string { + return execution.time.toPrecision(2); + } + getContextValue(execution: Execution): string { if (execution.status === "completed" || execution.status === "failed") { if (execution.stderr === "" && execution.stdout === "") { diff --git a/src/tree/functions/executions/ExecutionsTreeItem.ts b/src/tree/functions/executions/ExecutionsTreeItem.ts index 916d2e1..31ba091 100644 --- a/src/tree/functions/executions/ExecutionsTreeItem.ts +++ b/src/tree/functions/executions/ExecutionsTreeItem.ts @@ -1,11 +1,14 @@ import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode"; import { Execution, ExecutionList } from '../../../appwrite'; import { functionsClient } from "../../../client"; -import { AppwriteTreeItemBase } from '../../../ui/AppwriteTreeItemBase'; +import { AwTreeItem } from '../../common/AwTreeItem'; import { ExecutionTreeItem } from './ExecutionTreeItem'; import { FunctionTreeItem } from '../FunctionTreeItem'; +import { ext } from '../../../extensionVariables'; -export class ExecutionsTreeItem extends AppwriteTreeItemBase { +const executionsToShow = 10; + +export class ExecutionsTreeItem extends AwTreeItem { constructor(public readonly parent: FunctionTreeItem) { super(parent, "Executions"); } @@ -14,8 +17,10 @@ export class ExecutionsTreeItem extends AppwriteTreeItemBase { if (!functionsClient) { return []; } - const executions: ExecutionList | undefined = await functionsClient.listExecutions(this.parent.func.$id, undefined, undefined, undefined, 'DESC'); + const executions: ExecutionList | undefined = await functionsClient.listExecutions(this.parent.func.$id, undefined, executionsToShow, undefined, 'DESC'); const children = executions?.executions.map((execution: Execution) => new ExecutionTreeItem(this, execution)) ?? [new TreeItem('No exeuctions.')]; + ext.outputChannel.appendLog(`Found ${executions?.sum} executions`); + children.push(new TreeItem('View more')); return children; } diff --git a/src/tree/functions/settings/EventsTreeItem.ts b/src/tree/functions/settings/EventsTreeItem.ts index 2346b13..89bf252 100644 --- a/src/tree/functions/settings/EventsTreeItem.ts +++ b/src/tree/functions/settings/EventsTreeItem.ts @@ -3,7 +3,7 @@ import { Function } from "../../../appwrite"; import { functionsClient } from "../../../client"; import { appwriteSystemEvents } from "../../../constants"; import { ext } from "../../../extensionVariables"; -import { EnumEditableTreeItemBase } from "../../common/EnumEditableTreeItem"; +import { EnumEditableTreeItemBase } from "../../common/editable/EnumEditableTreeItem"; import { FunctionSettingsTreeItem } from "./FunctionSettingsTreeItem"; export class EventsTreeItem extends EnumEditableTreeItemBase { diff --git a/src/tree/functions/settings/FunctionSettingsTreeItem.ts b/src/tree/functions/settings/FunctionSettingsTreeItem.ts index 941c2a9..f374534 100644 --- a/src/tree/functions/settings/FunctionSettingsTreeItem.ts +++ b/src/tree/functions/settings/FunctionSettingsTreeItem.ts @@ -1,7 +1,7 @@ import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode"; import { Function } from "../../../appwrite"; import { functionsClient } from "../../../client"; -import { AppwriteTreeItemBase } from "../../../ui/AppwriteTreeItemBase"; +import { AwTreeItem } from "../../common/AwTreeItem"; import { ChildTreeItem } from "../../ChildTreeItem"; import { FunctionTreeItem } from "../FunctionTreeItem"; import { EventsTreeItem } from "./EventsTreeItem"; @@ -10,7 +10,7 @@ import { ScheduleTreeItem } from "./ScheduleTreeItem"; import { TimeoutTreeItem } from "./TimeoutTreeItem"; import { VarsTreeItem } from "./VarsTreeItem"; -export class FunctionSettingsTreeItem extends AppwriteTreeItemBase { +export class FunctionSettingsTreeItem extends AwTreeItem { public readonly func: Function; constructor(public readonly parent: FunctionTreeItem) { diff --git a/src/tree/functions/settings/NameTreeItem.ts b/src/tree/functions/settings/NameTreeItem.ts index 159fd0f..25f6c30 100644 --- a/src/tree/functions/settings/NameTreeItem.ts +++ b/src/tree/functions/settings/NameTreeItem.ts @@ -2,7 +2,7 @@ import { InputBoxOptions, MarkdownString } from "vscode"; import { Function } from "../../../appwrite"; import { functionsClient } from "../../../client"; import { ext } from "../../../extensionVariables"; -import { StringEditableTreeItemBase } from '../../common/StringEditableTreeItem'; +import { StringEditableTreeItemBase } from '../../common/editable/StringEditableTreeItem'; import { FunctionSettingsTreeItem } from "./FunctionSettingsTreeItem"; const tooltip = "Function name"; diff --git a/src/tree/functions/settings/ScheduleTreeItem.ts b/src/tree/functions/settings/ScheduleTreeItem.ts index de2e3bb..10a2e15 100644 --- a/src/tree/functions/settings/ScheduleTreeItem.ts +++ b/src/tree/functions/settings/ScheduleTreeItem.ts @@ -5,7 +5,7 @@ import { ext } from "../../../extensionVariables"; import cron from "cron-validate"; import { FunctionSettingsTreeItem } from "./FunctionSettingsTreeItem"; import cronstrue from "cronstrue"; -import { StringEditableTreeItemBase } from '../../common/StringEditableTreeItem'; +import { StringEditableTreeItemBase } from '../../common/editable/StringEditableTreeItem'; export class ScheduleTreeItem extends StringEditableTreeItemBase { private readonly func: Function; diff --git a/src/tree/functions/settings/TimeoutTreeItem.ts b/src/tree/functions/settings/TimeoutTreeItem.ts index 3b5da4c..b2e8a62 100644 --- a/src/tree/functions/settings/TimeoutTreeItem.ts +++ b/src/tree/functions/settings/TimeoutTreeItem.ts @@ -2,7 +2,7 @@ import { InputBoxOptions, MarkdownString } from "vscode"; import { Function } from "../../../appwrite"; import { functionsClient } from "../../../client"; import { ext } from "../../../extensionVariables"; -import { StringEditableTreeItemBase } from "../../common/StringEditableTreeItem"; +import { StringEditableTreeItemBase } from "../../common/editable/StringEditableTreeItem"; function isNumeric(str: string) { console.log("here"); diff --git a/src/tree/functions/settings/VarTreeItem.ts b/src/tree/functions/settings/VarTreeItem.ts index c1134b8..cd64572 100644 --- a/src/tree/functions/settings/VarTreeItem.ts +++ b/src/tree/functions/settings/VarTreeItem.ts @@ -2,7 +2,7 @@ import { InputBoxOptions, MarkdownString, window } from "vscode"; import { Function } from "../../../appwrite"; import { functionsClient } from "../../../client"; import { ext } from "../../../extensionVariables"; -import { StringEditableTreeItemBase } from "../../common/StringEditableTreeItem"; +import { StringEditableTreeItemBase } from "../../common/editable/StringEditableTreeItem"; import { VarsTreeItem } from "./VarsTreeItem"; const tooltip = "Environment var"; diff --git a/src/tree/functions/settings/VarsTreeItem.ts b/src/tree/functions/settings/VarsTreeItem.ts index e66496b..be05509 100644 --- a/src/tree/functions/settings/VarsTreeItem.ts +++ b/src/tree/functions/settings/VarsTreeItem.ts @@ -1,10 +1,10 @@ import { TreeItem, TreeItemCollapsibleState } from "vscode"; import { Vars } from "../../../appwrite"; -import { AppwriteTreeItemBase } from "../../../ui/AppwriteTreeItemBase"; +import { AwTreeItem } from "../../common/AwTreeItem"; import { FunctionSettingsTreeItem } from "./FunctionSettingsTreeItem"; import { VarTreeItem } from "./VarTreeItem"; -export class VarsTreeItem extends AppwriteTreeItemBase { +export class VarsTreeItem extends AwTreeItem { public readonly vars: Vars; constructor(parent: FunctionSettingsTreeItem) { diff --git a/src/tree/functions/tags/TagsTreeItem.ts b/src/tree/functions/tags/TagsTreeItem.ts index 3f65829..f093275 100644 --- a/src/tree/functions/tags/TagsTreeItem.ts +++ b/src/tree/functions/tags/TagsTreeItem.ts @@ -1,10 +1,11 @@ import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode"; import { functionsClient } from "../../../client"; -import { AppwriteTreeItemBase } from '../../../ui/AppwriteTreeItemBase'; +import { AwParentTreeItem } from '../../common/AwParentTreeItem'; +import { AwTreeItem } from '../../common/AwTreeItem'; import { FunctionTreeItem } from '../FunctionTreeItem'; import { TagTreeItem } from './TagTreeItem'; -export class TagsTreeItem extends AppwriteTreeItemBase { +export class TagsTreeItem extends AwParentTreeItem { constructor(public readonly parent: FunctionTreeItem) { super(parent, "Tags"); } diff --git a/src/utils/date.ts b/src/utils/date.ts index f5da0cc..dba032f 100644 --- a/src/utils/date.ts +++ b/src/utils/date.ts @@ -1,5 +1,9 @@ -import dayjs = require('dayjs'); +import dayjs = require("dayjs"); +import utc = require("dayjs/plugin/utc"); +import timezone = require("dayjs/plugin/timezone"); // dependent on utc plugin +dayjs.extend(utc); +dayjs.extend(timezone); export function msToDate(ms: number): string { - return dayjs(ms).format("LTS"); + return dayjs(ms * 1000).tz("America/Chicago").format("LTS"); } diff --git a/src/utils/sleep.ts b/src/utils/sleep.ts new file mode 100644 index 0000000..2b5e993 --- /dev/null +++ b/src/utils/sleep.ts @@ -0,0 +1,5 @@ +export function sleep(ms: number): Promise { + return new Promise((resolve) => { + setTimeout(resolve, ms); + }); +} diff --git a/src/utils/tar.ts b/src/utils/tar.ts index 8f81821..f8a8317 100644 --- a/src/utils/tar.ts +++ b/src/utils/tar.ts @@ -2,8 +2,8 @@ import tar = require("tar"); import { Uri, window, workspace } from "vscode"; import { ext } from "../extensionVariables"; import * as path from "path"; -import * as os from "os"; import * as fs from "fs"; +import { sleep } from './sleep'; export async function getTarReadStream(folder: Uri): Promise { try { @@ -15,11 +15,14 @@ export async function getTarReadStream(folder: Uri): Promise window.showErrorMessage("No workspace open."); return; } + ext.outputChannel.appendLog(`Creating '${tarName}' in '${workspace.workspaceFolders?.[0].uri.fsPath}'...`); + const tarFilePath = path.join(ext.context?.globalStorageUri.fsPath ?? '', tarName); + await workspace.fs.createDirectory(ext.context.globalStorageUri); - const tarFilePath = path.join(os.tmpdir(), tarName); + tar.create({ gzip: true, cwd: cwd, mode: 1777 }, [path.relative(cwd, folder.fsPath)]).pipe(fs.createWriteStream(tarFilePath)); - tar.create({ gzip: true, cwd: cwd }, [path.relative(cwd, folder.fsPath)]).pipe(fs.createWriteStream(tarFilePath)); + await sleep(500); ext.outputChannel.appendLog(`Created ${tarFilePath}`); diff --git a/src/utils/types.d.ts b/src/utils/types.d.ts new file mode 100644 index 0000000..9ab797c --- /dev/null +++ b/src/utils/types.d.ts @@ -0,0 +1,6 @@ +import { Progress } from 'vscode'; + +export type ProgressMessage = Progress<{ + message?: string | undefined; + increment?: number | undefined; +}>;