function tag creation
This commit is contained in:
parent
5eca23247a
commit
7624a7fc77
32 changed files with 180 additions and 74 deletions
|
@ -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<void> {
|
||||
return await AppwriteCall(this.functions.delete(functionId));
|
||||
}
|
||||
public async createTag(functionId: string, command: string, code: ReadStream): Promise<any> {
|
||||
public async createTag(functionId: string, command: string, code: ReadStream): Promise<Tag | undefined> {
|
||||
return await AppwriteCall(this.functions.createTag(functionId, command, code));
|
||||
}
|
||||
public async listTags(id: string, search?: string, limit?: number, offset?: number, orderType?: 'ASC' | 'DESC'): Promise<TagList | undefined> {
|
||||
|
@ -40,7 +40,7 @@ export class Functions {
|
|||
public async deleteTag(functionId: string, tagId: string): Promise<void> {
|
||||
return await AppwriteCall(this.functions.deleteTag(functionId, tagId));
|
||||
}
|
||||
public async createExecution(functionId: string, data?: string): Promise<any> {
|
||||
public async createExecution(functionId: string, data?: string): Promise<Execution | undefined> {
|
||||
return await AppwriteCall(this.functions.createExecution(functionId, data));
|
||||
}
|
||||
public async listExecutions(functionId: string, search?: string, limit?: number, offset?: number, orderType?: 'ASC' | 'DESC'): Promise<ExecutionList | undefined> {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { EditableTreeItem } from '../../tree/common/SimpleEditableTreeItem';
|
||||
import { EditableTreeItem } from '../../tree/common/editable/SimpleEditableTreeItem';
|
||||
|
||||
export async function editValue(treeItem: EditableTreeItem): Promise<void> {
|
||||
if (treeItem === undefined) {
|
||||
|
|
|
@ -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<void> {
|
||||
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<void> {
|
||||
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<Execution | undefined> {
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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<void> {
|
||||
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<void> {
|
||||
const tarFilePath = await getTarReadStream(uri);
|
||||
async function createTagFromUri(uri: Uri, progress: ProgressMessage): Promise<Tag | undefined> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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<void> {
|
||||
export async function viewExecutionErrors(executionItem: ExecutionTreeItem | Execution): Promise<void> {
|
||||
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');
|
||||
}
|
||||
|
|
|
@ -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<void> {
|
||||
export async function viewExecutionOutput(executionItem: ExecutionTreeItem | Execution): Promise<void> {
|
||||
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');
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ export type AppwriteTree = {
|
|||
};
|
||||
|
||||
export type Ext = {
|
||||
context?: ExtensionContext;
|
||||
context: ExtensionContext;
|
||||
outputChannel: AppwriteOutputChannel;
|
||||
tree?: AppwriteTree;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<vscode.TreeItem> {
|
||||
private _onDidChangeTreeData: vscode.EventEmitter<vscode.TreeItem | undefined | void> = new vscode.EventEmitter<
|
||||
|
@ -33,8 +33,8 @@ export class DatabaseTreeItemProvider implements vscode.TreeDataProvider<vscode.
|
|||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
if (parent instanceof AppwriteTreeItemBase) {
|
||||
return parent.getChildren?.() ?? [];
|
||||
if (parent instanceof AwParentTreeItem) {
|
||||
return parent.getChildrenInternal() ?? [];
|
||||
}
|
||||
|
||||
const databaseSdk = new AppwriteSDK.Database(client);
|
||||
|
|
|
@ -3,12 +3,12 @@ import { DocumentsList } from "../../appwrite";
|
|||
import { client } from "../../client";
|
||||
import { AppwriteSDK } from "../../constants";
|
||||
import { ext } from "../../extensionVariables";
|
||||
import { AppwriteTreeItemBase } from "../../ui/AppwriteTreeItemBase";
|
||||
import { AwTreeItem } from "../common/AwTreeItem";
|
||||
import AppwriteCall from "../../utils/AppwriteCall";
|
||||
import { CollectionTreeItem } from "./CollectionTreeItem";
|
||||
import { DocumentTreeItem } from "./DocumentTreeItem";
|
||||
|
||||
export class DocumentsTreeItem extends AppwriteTreeItemBase<CollectionTreeItem> {
|
||||
export class DocumentsTreeItem extends AwTreeItem<CollectionTreeItem> {
|
||||
constructor(parent: CollectionTreeItem) {
|
||||
super(parent, "Documents");
|
||||
}
|
||||
|
|
|
@ -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<CollectionTreeItem> {
|
||||
export class PermissionsTreeItem extends AwTreeItem<CollectionTreeItem> {
|
||||
public readonly permissions: Permissions;
|
||||
|
||||
constructor(parent: CollectionTreeItem) {
|
||||
|
|
|
@ -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<CollectionTreeItem> {
|
||||
export class RulesTreeItem extends AwTreeItem<CollectionTreeItem> {
|
||||
public readonly rules: Rule[];
|
||||
|
||||
constructor(parent: CollectionTreeItem) {
|
||||
|
|
|
@ -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)}`);
|
||||
|
|
|
@ -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<vscode.TreeItem> {
|
||||
private _onDidChangeTreeData: EventEmitter<TreeItem | undefined | void> = new EventEmitter<TreeItem | undefined | void>();
|
||||
|
@ -25,7 +26,7 @@ export class FunctionsTreeItemProvider implements vscode.TreeDataProvider<vscode
|
|||
return element;
|
||||
}
|
||||
|
||||
async getChildren(parent?: AppwriteTreeItemBase | TreeItem): Promise<vscode.TreeItem[]> {
|
||||
async getChildren(parent?: AwTreeItem | TreeItem): Promise<vscode.TreeItem[]> {
|
||||
if (client === undefined) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
@ -43,8 +44,8 @@ export class FunctionsTreeItemProvider implements vscode.TreeDataProvider<vscode
|
|||
return [{ label: "No functions found" }];
|
||||
}
|
||||
|
||||
if (parent instanceof AppwriteTreeItemBase) {
|
||||
return parent.getChildren?.() ?? [];
|
||||
if (parent instanceof AwParentTreeItem) {
|
||||
return parent.getChildren();
|
||||
}
|
||||
|
||||
return [];
|
||||
|
|
|
@ -3,6 +3,7 @@ import { Execution, ExecutionStatus } from "../../../appwrite";
|
|||
import { functionsClient } from "../../../client";
|
||||
import { ext } from "../../../extensionVariables";
|
||||
import { msToDate } from "../../../utils/date";
|
||||
import { sleep } from '../../../utils/sleep';
|
||||
import { ExecutionsTreeItem } from "./ExecutionsTreeItem";
|
||||
|
||||
const executionStatusIcons: Record<ExecutionStatus, ThemeIcon> = {
|
||||
|
@ -12,17 +13,11 @@ const executionStatusIcons: Record<ExecutionStatus, ThemeIcon> = {
|
|||
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<void> {
|
||||
|
@ -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 === "") {
|
||||
|
|
|
@ -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<FunctionTreeItem> {
|
||||
const executionsToShow = 10;
|
||||
|
||||
export class ExecutionsTreeItem extends AwTreeItem<FunctionTreeItem> {
|
||||
constructor(public readonly parent: FunctionTreeItem) {
|
||||
super(parent, "Executions");
|
||||
}
|
||||
|
@ -14,8 +17,10 @@ export class ExecutionsTreeItem extends AppwriteTreeItemBase<FunctionTreeItem> {
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<FunctionTreeItem> {
|
||||
export class FunctionSettingsTreeItem extends AwTreeItem<FunctionTreeItem> {
|
||||
public readonly func: Function;
|
||||
|
||||
constructor(public readonly parent: FunctionTreeItem) {
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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<FunctionSettingsTreeItem> {
|
||||
export class VarsTreeItem extends AwTreeItem<FunctionSettingsTreeItem> {
|
||||
public readonly vars: Vars;
|
||||
|
||||
constructor(parent: FunctionSettingsTreeItem) {
|
||||
|
|
|
@ -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<FunctionTreeItem> {
|
||||
export class TagsTreeItem extends AwParentTreeItem {
|
||||
constructor(public readonly parent: FunctionTreeItem) {
|
||||
super(parent, "Tags");
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
5
src/utils/sleep.ts
Normal file
5
src/utils/sleep.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
export function sleep(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
|
@ -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<string | undefined> {
|
||||
try {
|
||||
|
@ -15,11 +15,14 @@ export async function getTarReadStream(folder: Uri): Promise<string | undefined>
|
|||
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}`);
|
||||
|
||||
|
|
6
src/utils/types.d.ts
vendored
Normal file
6
src/utils/types.d.ts
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
import { Progress } from 'vscode';
|
||||
|
||||
export type ProgressMessage = Progress<{
|
||||
message?: string | undefined;
|
||||
increment?: number | undefined;
|
||||
}>;
|
Loading…
Reference in a new issue