npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sisense/task-manager

v0.1.1

Published

Solution for management of your resource-intensive and time-consuming tasks

Downloads

10,663

Readme

task-manager

What is a task-manager?

This library helps solve the common development problem of managing complex, resource-intensive asynchronous tasks (workflows).

Imagine you have a request for a Service that needs to execute a sequential workflow consisting of several lengthy asynchronous steps in order to return the final result.

Multi-step request

If this task takes a significant amount of time, the user may want to cancel it manually or by timeout. If this task has multiple lengthy asynchronous steps and a cancel request can be made at any point in this complex flow, you would want to cancel it as soon as possible and skip all subsequent steps. Each step's cancellation may require its own logic to clean up and free consumed resources.

Service with manager

If resources for doing smth 1 or doing smth 2 are limited - you may want to add some internal Queue to collect incoming requests and perform the execution of these workflow steps one by one.

In task-manager this possibility implemented as an addon and can be optionally added if needed. The basic behavior of task-manager includes only canceling logic.


The main idea of task-manager:

  • You create your own TaskManager where define ExecutionFlow. ExecutionFlow made of Steps - for each Step you define RunLogic - async function that performs logic you want to do, like doing smth 1, and CancelLogic - async function that performs all cleaning up you want to do if canceling happened during this step.

  • On incoming request, you create TaskPassport that contains the type of task and payload of your request.

  • Save taskId of the task you are performing to be able to cancel it if needed.

const STEP_2_RESULT = 'step_2_result';
const SOME_RUNTIME_VALUE = 'some_runtime_value';

const step1 = new Step(
    'step_1_name',
    async (task: MyTask) => {
        // do something 1
        task.addRuntimeInfo('someRuntimeValue', SOME_RUNTIME_VALUE);
        // return nothing
    },
    async () => {
        // clean up if canceled during step 1
    },
);
const step2 = new Step(
    'step_2_name',
    async () => {
        // do something 2
        return STEP_2_RESULT;
    },
    async () => {
        // clean up if canceled during step 2
    },
);

class MyTaskManager extends AbstractTaskManager {
    executeTestFlow = super.createFlow<MyTaskPassport, MyTaskRuntimeInfo, MyTaskResultData>([
        step1,
        step2,
    ]);
}

const manager = new MyTaskManager();
// for each incoming request
const taskPassport = new MyTaskPassport(/* payload */);
const result = await manager.executeTestFlow(taskPassport);

// if cancel request ->
manager.cancel(taskPassport.taskId);

// cancel by timeout
setTimeout(() => {
    manager.cancel(taskPassport.taskId);
}, 1000);