This README will guide you on how to set up Unmeshed credentials, run workers, and get started with the Unmeshed platform. Read more about unmeshed on https://unmeshed.io/
Unmeshed is a ⚡ fast, low latency orchestration platform, that can be used to 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 is the next gen platform built using similar principles but is blazing fast and covers many more use cases.
To use Unmeshed in your project, install the SDK using your preferred package manager:
npm install @unmeshed/sdk
yarn add @unmeshed/sdk
To use the Unmeshed SDK in your Node.js app, you need to initialize the UnmeshedClient
with your credentials. Replace
the placeholder values below with your actual credentials:
const {UnmeshedClient} = require("@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, leverage webhooks and user tokens 🔑 directly.
You can get started with Unmeshed by visiting our 📘 Get Started Guide.
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) => {
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]);
You can run as many workers as you want.
Et voilà — that's it! Now whenever a process definition or worker reaches this step with name test-node-worker, it will run your function
The
startPolling
method starts the worker to listen 👂 for tasks continuously.
When you run your Node.js app, and the worker will start polling for tasks automatically 🤖.
// processId: number, includeSteps: boolean
const processData = await unmeshedClient.getProcessData(processId, includeSteps);
// stepId: number
const stepData = await unmeshedClient.getStepData(stepId);
const request = {
name: `your-process-name`,
version: null, // null = latest, specify a version if required
namespace: `default`,
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);
const request = {
name: `your-process-name`,
version: null, // null = latest, specify a version if required
namespace: `default`,
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.runProcessAsync(request);
Difference between sync and async is just the method you call.
runProcessSync
vsrunProcessAsync
Terminates multiple processes in bulk based on the provided process IDs.
const processIds = [1, 2, 3];
const reason = "Terminating due to policy changes";
const response = await unmeshedClient.bulkTerminate(processIds, reason);
console.log(response);
- processIds (array of numbers): The IDs of the processes to terminate.
- reason (string, optional): The reason for terminating the processes.
- ProcessActionResponseData: The response containing the status of the termination.
Resumes multiple processes in bulk based on the provided process IDs.
const processIds = [1, 2, 3];
const response = await unmeshedClient.bulkResume(processIds);
console.log(response);
- processIds (array of numbers): The IDs of the processes to resume.
- ProcessActionResponseData: The response containing the status of the resumption.
Marks multiple processes as reviewed based on the provided process IDs.
const processIds = [1, 2, 3];
const reason = "Reviewed for compliance";
const response = await unmeshedClient.bulkReviewed(processIds, reason);
console.log(response);
- processIds (array of numbers): The IDs of the processes to mark as reviewed.
- reason (string, optional): The reason for marking the processes as reviewed.
- ProcessActionResponseData: The response containing the status of the review action.
Reruns a specific process based on its ID, client ID, and optionally a version.
const processId = 123;
const version = 2; // Optional, empty if you want to run latest
const response = await unmeshedClient.rerun(processId, version);
console.log(response);
- processId (number): The ID of the process to rerun.
- version (number, optional): The version of the process to rerun.
- ProcessData: The data of the rerun process.
Searches for process executions based on the provided search criteria.
const searchParams = {
startTimeEpoch: 1622505600000,
endTimeEpoch: 1622505800000,
namespace: "default",
names: ["process1", "process2"],
processIds: [1, 2, 3],
correlationIds: ["corr1", "corr2"],
requestIds: ["req1", "req2"],
statuses: ["RUNNING", "COMPLETED"],
triggerTypes: ["MANUAL", "API"]
};
const response = await unmeshedClient.searchProcessExecutions(searchParams);
console.log(response);
- startTimeEpoch (number, optional): The start time in epoch format.
- endTimeEpoch (number, optional): The end time in epoch format.
- namespace (string, optional): The namespace to filter the processes.
- names (array of strings, optional): The names of the processes.
- processIds (array of numbers, optional): The IDs of the processes.
- correlationIds (array of strings, optional): The correlation IDs of the processes.
- requestIds (array of strings, optional): The request IDs of the processes.
- statuses (array of strings, optional): The statuses of the processes.
- triggerTypes (array of strings, optional): The trigger types of the processes.
- Response data containing the search results.
- 📖 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!