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

qz-jobqueue

v1.0.4

Published

queue utils for long time jobs

Downloads

1

Readme

JobQueue

utils for long time jobs ##JobQueue A simple job queue to process data one by one. let queue = new JobQueue({consumer:xxx,interval:xxx,timeout}); consumer is a process function with protocol as: function(data){...}, comsumer must return a promise; interval is the delay time before two action,default is 0ms time is the delay time if job execution failed. default is 100ms

how to work

ask consumer to process data:

queue.push(somedata);
queue.push(next_data);

next_data will be process only when somedata is processed;

return queue.push(somedata).then(()=>{
    queue.push(next_data)
})

Similar as above, but a promise will be returned;

Add timeout for procedure:

return queue.push(somedata,500).then(()=>{ queue.push(next_data,1000) }) The promise will reject 'timeout' exception when somedata not have been processed in 500 ms, same as next_data;

queue.push(somedata,500);
return queue.push(next_data,1000);

next_data should be processed in 1000ms, including the process time of somedata; queue.pause pause proceed after current one finished. queue.resume resume to start proceed data

##JobQueue 一个简单的任务队列,实现逐个处理数据的功能

let queue = new JobQueue({consumer:xxx,interval:xxx});

consumer是一个处理函数,其函数原型为function(data){ return Promise;},一定返回一个promise interval 是两次处理之间的时间间隔,默认为0ms
timeout 是某次数据失败后,处理下一次数据的恢复时间,默认为100ms

需要队列处理数据的时候:

queue.push(somedata);
queue.push(next_data);
 

队列会在somedata处理完毕后,自动处理next_data

queue.pause  暂停处理数据
queue.resume 恢复处理数据

#WriteQueue simple queue for update specified state

!!not tested!!

Some state, such as light state in smarthome, if multiple command is sent in a short time, it would be nonsense to switch the light multi-times. Let's think about such command sequence:

    on--> off -->off -->on -->off-->on

suppose controlling the light will cause 500ms to 2 seconds due to different network situation,when first command (on) is processed an returned there are many request pended in queue but the last command is same as current state. So all other command should be ignored.

the class WriteQueue is build for this propose:

   let writeQueue = new WriteQueue({consumer:xxx});

consumer is a process function with protocol as: function(data){...}, comsumer must return a promise;

how to work

ask consumer to process data:

writeQueue.push(somedata,uuid,timeout);
writeQueue.push(next_data,uuid,timeout);
writeQueue.push(next_data2,uuid,timeout);

When somedata is process and returned writeQueue will check all data in its cache(next_data,next_data2); In this case, next_data will be ignored, and if next_data2 is same as somedata, no more action will execute; if different, comsumer(next_data2) will be called.

timeout is used to set the most execute time;

'resp-'+uuid event will fired when processed, with data:

{
    success: true/false,  exection state  
    reason: xxx           when failed, this is the reason
    result:   if success, this is the return value
}