Skip to content

Commit

Permalink
Update from fluxninja/aperture
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxninjaops committed Nov 20, 2023
1 parent 5bf24db commit 10645c1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
35 changes: 18 additions & 17 deletions example/routes/use_aperture.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express from "express";
import { ApertureClient, Flow, FlowStatusEnum } from "@fluxninja/aperture-js";
import { ApertureClient, Flow, FlowStatusEnum, LookupStatus } from "@fluxninja/aperture-js";
import grpc from "@grpc/grpc-js";


Expand Down Expand Up @@ -39,27 +39,28 @@ apertureRoute.get("/", async (_: express.Request, res: express.Response) => {

if (flow.ShouldRun()) {
await sleep(200);
console.log("Work done!");

if (flow.CachedValue().GetLookupStatus() === LookupStatus.Hit) {
console.log("Cache hit:", flow.CachedValue().GetValue()?.toString());
} else {
console.log("Cache miss:", flow.CachedValue().GetOperationStatus(), flow.CachedValue().GetError()?.message);
const resString = "awesomeString";

// create a new buffer
const buffer = Buffer.from(resString);

// set cache value
const setResult = await flow.SetCachedValue(buffer, { seconds: 30, nanos: 0 })
if (setResult?.error) {
console.log(`Error setting cache value: ${setResult.error}`);
}
}

res.sendStatus(202);
} else {
flow.SetStatus(FlowStatusEnum.Error);
res.sendStatus(403);
}

// create a new buffer
const buffer = Buffer.from("awesomeString");

// set cache value
const setResult = await flow.SetCachedValue(buffer, { seconds: 30, nanos: 0 })
if (setResult?.error) {
console.log(`Error setting cache value: ${setResult.error}`);
}

// delete cache value
const deleteResult = await flow.DeleteCachedValue()
if (deleteResult?.error) {
console.log(`Error deleting cache value: ${deleteResult.error}`);
}
} catch (e) {
console.log(e);
res.status(500).send(`Error occurred: ${e}`);
Expand Down
2 changes: 1 addition & 1 deletion sdk/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function ConvertCacheOperationStatus(
export function ConvertCacheError(
error: string | null | undefined,
): Error | null {
if (error === null || error === undefined) {
if (!error) {
return null;
}
return new Error(error);
Expand Down
1 change: 1 addition & 0 deletions sdk/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./client.js";
export * from "./flow.js";
export * from "./cache.js";

0 comments on commit 10645c1

Please sign in to comment.