Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
flesh out kv example
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Heric committed Dec 13, 2023
1 parent b6e6875 commit faafeb9
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/sandbox/kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Audience } from "@streamdal/protos/protos/sp_common";

import { OperationType, Streamdal, StreamdalConfigs } from "../streamdal.js";
import { loadData } from "./billing.js";
import { runPipeline } from "./index.js";

const serviceKVConfig: StreamdalConfigs = {
streamdalUrl: "localhost:8082",
Expand All @@ -20,9 +19,6 @@ const KVProducer: Audience = {
operationName: "import",
};

const welcome = new Streamdal(serviceKVConfig);
const wpData = loadData("./src/sandbox/assets/sample-welcome-producer.json");

/**
* 1. run this
* 2. go to the console, create a pipeline with a "Key/Value" step type,
Expand All @@ -36,10 +32,34 @@ const wpData = loadData("./src/sandbox/assets/sample-welcome-producer.json");
* "http://localhost:8081/api/v1/kv"
*/
export const kv = () => {
const kvService = new Streamdal(serviceKVConfig);
const kvData = loadData("./src/sandbox/assets/sample-welcome-producer.json");

//
// Key exists, this will result in a pipeline step running without error
runPipeline(welcome, KVProducer, wpData[0], 1000);
// eslint-disable-next-line @typescript-eslint/no-misused-promises
setInterval(async () => {
const result = await kvService.process({
audience: KVProducer,
data: new TextEncoder().encode(JSON.stringify(kvData[0])),
});

//
// Key exists, this will result in a pipeline step running without error
// if this is part of multi-step or multi-pipeline you will need to inspect pipelineStatus
console.debug(result.error);
}, 1000);

//
// Key does not exist, this will result in a pipeline step running without error
runPipeline(welcome, KVProducer, wpData[1], 1000);
// eslint-disable-next-line @typescript-eslint/no-misused-promises
setInterval(async () => {
const result = await kvService.process({
audience: KVProducer,
data: new TextEncoder().encode(JSON.stringify(kvData[1])),
});

//
// Key does not exist, this will result in an error
// if this is part of multi-step or multi-pipeline you will need to inspect pipelineStatus
console.debug(result.error);
}, 1000);
};

0 comments on commit faafeb9

Please sign in to comment.