This README will guide you through setting up Unmeshed credentials, running workers, and using the Unmeshed SDK with TypeScript. Read more about Unmeshed on https://unmeshed.io/.
Unmeshed is a β‘ fast, low-latency orchestration platform that helps you build π οΈ, run π, and scale π API and microservices orchestration, scheduled jobs β°, and more with ease. Learn more on our π main website or explore the π documentation overview.
Unmeshed is built by the ex-founders of Netflix Conductor. This next-gen platform is blazing fast and covers many more use cases.
To use Unmeshed in your TypeScript project, install the SDK using your preferred package manager:
npm install @unmeshed/sdk
yarn add @unmeshed/sdk
To initialize the UnmeshedClient
with your credentials, use the following code snippet. Replace the placeholder values
with your actual credentials:
import {UnmeshedClient} from '@unmeshed/sdk';
const unmeshedClient = new UnmeshedClient({
baseUrl: 'http://localhost', // Replace with your Unmeshed API endpoint π
port: 8080, // Replace with your Unmeshed API port πͺ
authToken: 'your-auth-token', // Replace with your API π auth token
clientId: 'your-client-id' // Replace with your API π client ID
});
Note: Do not expose these credentials in a browser π. For browser implementations, use webhooks and user tokens π directly.
A worker in Unmeshed processes π tasks asynchronously based on workflows or process definitions. Below is an example of defining and starting a worker:
A worker function processes incoming tasks and returns an output:
let workerFunction = (input: any): Promise<any> => {
return new Promise((resolve) => {
const output = {
...input || {},
"ranAt": new Date() // Add the current timestamp to the output π
};
resolve(output);
});
};
Define the worker configuration and register it with the UnmeshedClient
:
const worker = {
worker: workerFunction,
namespace: 'default', // Namespace for the worker ποΈ
name: 'test-node-worker', // Unique name for the worker π·οΈ
maxInProgress: 500 // Maximum number of in-progress tasks β³
};
unmeshedClient.startPolling([worker]);
The
startPolling
method starts the worker to listen π for tasks continuously.
When you run your TypeScript app, the worker will automatically start polling for tasks π€.
import {ProcessRequestData} from '@unmeshed/sdk';
const request: ProcessRequestData = {
namespace: `default`,
name: `testing`,
version: null, // null = latest, specify a version if required
requestId: `my-id-1`, // Your id (Optional)
correlationId: `my-crid-1`, // Your correlation id (Optional)
input: { // Inputs to your process
"mykey": "value",
"mykeyNumber": 100,
"mykeyBoolean": true
}
};
const processData = await unmeshedClient.runProcessSync(request);
console.log("Output: ", processData);
const pd = await unmeshedClient.getProcessData(processData.processId, true);
console.log("Output of process including steps ", pd);
const pdWithoutSteps = await unmeshedClient.getProcessData(processData.processId, false);
console.log("Output of process without steps ", pdWithoutSteps);
const stepData = await unmeshedClient.getStepData(pd.steps[0].id);
console.log("Output of the first step in process ", stepData);
const processIds = [1, 2, 3];
const reason = "Terminating due to policy changes";
const bulkTerminateOutput = await unmeshedClient.bulkTerminate(processIds, reason);
console.log("Output of the bulk terminate action ", bulkTerminateOutput);
const bulkResumeOutput = await unmeshedClient.bulkResume(processIds);
console.log("Output of the bulk resume action ", bulkResumeOutput);
const bulkReviewedOutput = await unmeshedClient.bulkReviewed(processIds, reason);
console.log("Output of the bulk review action ", bulkReviewedOutput);
const rerun = await unmeshedClient.reRun(processData.processId);
console.log("Output of the rerun action ", rerun);
const searchParams = {
startTimeEpoch: 1737091430310, // Start time in epoch milliseconds
endTimeEpoch: 0, // End time in epoch milliseconds (0 indicates no end time, Optional)
namespace: "default", // Namespace for the search, (Optional)
processTypes: [ProcessType.STANDARD], // Array of process types to filter by, (Optional)
triggerTypes: [ProcessTriggerType.MANUAL], // Array of trigger types to filter by, (Optional)
names: ["new_worker"], // Array of process names to search for, (Optional)
processIds: [3200041], // Array of process IDs to filter by, (Optional)
correlationIds: [""], // Array of correlation IDs, (Optional)
requestIds: ["34f1fc6c-a08e-4feb-82be-7d4b329f484b"], // Array of request IDs to filter by, (Optional)
statuses: [ProcessStatus.COMPLETED], // Array of process statuses to filter by, (Optional)
limit: 10, // Maximum number of results to return, (Optional)
offset: 0, // Offset for pagination, (Optional)
};
const response = await unmeshedClient.searchProcessExecution(searchParams);
console.log(response);
- π Workers Documentation: Learn more about workers and how to use them effectively.
- Use Case Highlights:
For more details, visit our π documentation. If you encounter issues, feel free to reach out or open an issue in this repository!