Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dataparty/tasker

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dataparty/tasker

dependency solving task runner

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
2
Weekly downloads
 
Created
Source

Tasker

stablelicense

Tasker is a parallel task runner with dependency resolution and results collection.

Design

Tasker provides a Runner class which manages depedencies, tasks and results. The runner class utilizes the dependency-solver npm package. When possible upto Runner.parallel foreground tasks will be run at the same time. When background tasks are added to the Runner they are started immeditaly and do not count against the parallel limit.

Tasks are added to the Runner by calling Runner.addTask(task). Every Runner.planningIntervalMs added tasks have their dependencies reveiwed and the schedule is updated. Tasks are scheduled in order of:

  1. Order of calls to Runner.addTask(task)
  2. Task with no dependencies
  3. Task with depenedencies, in order after solving usage graph

As tasks are completed they can resolve with a result (or not). Any task that has defined dependencies will receive a reference to the task they depend upon in the depends argument passed to Task.exec({task, depends})

Consumers of the library are expected to extend the Task class to later instantiate and add instances to a runner. Tasks are added by calling Runner.addTask(task).

For more details see documentation:

Foreground Tasks

By default tasks are in the foreground. Tasks can be defined either with a function or by subclassing. See a complete tutorial.

Define task using function

let sleepThirty = async ()=>{
  return new Promise((resolve,reject)=>{
    setTimeout(resolve, 30*1000)
  })
}

let myTask = Tasker.Task({
  name: 'sleep-30',
  exec: sleepThirty
})

runner.addTask(myTask)

Define task with subclass

class SleepTask extends Tasker.Task {
  constructor(durationMs){
    this.duration = durationMs
    this.timeout = null
  }

  async exec(){
    return new Promise((resolve,reject)=>{

        this.timeout = setTimeout(this.onTimeout.bind(this), 30*1000)

      })
    }
  }

  onTimeout(){
    this.timeout = null
    console.log('sleep complete')
  }

  stop(){
    if(this.timeout !== null){
      clearTimeout(this.timeout)
      this.timeout = null
    }
  }
}


let sleepThirty = new SleepTaks(30*1000)

runner.addTask(sleepThirty)
runner.start()

Background Tasks

Background tasks do not count against the parallel task limit. On failure background tasks are restarted immediatly and will be kept running indefinitly. Background tasks only ever stop if they are explicitly cancelled.

How to implement a background task

Keywords

FAQs

Package last updated on 08 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc