
Security News
arXiv Is Rate Limiting Authors Following a Flood of AI Slop Submissions
arXiv now limits authors to two submissions a month as AI slop overwhelms moderators, delays good papers, and sparks debate over applying the limit to everyone.
@inventaire/level-jobs
Advanced tools
Job Queue in LevelDB for Node.js
$ npm install level-jobs --save
import level from 'classic-level'
const db = level('./db')
import Jobs from 'level-jobs'
This function will take care of a work unit.
async function worker(id, payload) {
await doSomething()
}
This function gets 3 arguments:
id uniquely identifies a job to be executed.payload contains everyting worker need to process the job.If the function throws an error, the work unit is retried.
const queue = Jobs(db, worker)
This database will be at the mercy and control of level-jobs, don't use it for anything else!
(this database can be a root levelup database or a sublevel)
You can define a maximum concurrency (the default is Infinity):
const maxConcurrency = 2
const queue = Jobs(db, worker, maxConcurrency)
As an alternative the third argument can be an options object with these defaults:
const options = {
maxConcurrency: Infinity,
maxRetries: 10,
workerTimeout: Infinity,
batchLength: 1,
backoff: {
randomisationFactor: 0,
initialDelay: 10,
maxDelay: 300
}
// preWorker: async () => {} // No preWorker hook set by default, but you can set one, for instance to wait for worker dependencies without this time being counted in the workerTimeout
}
const queue = Jobs(db, worker, options)
const payload = { what: 'ever' }
try {
const jobId = await queue.push(payload))
} catch (err) {
console.error('Error pushing work into the queue', err.stack)
}
or in batch:
const payloads = [
{ what: 'ever' },
{ what: 'ever' }
]
try {
const jobIds = await queue.pushBatch(payloads)
} catch (err) {
console.error('Error pushing works into the queue', err.stack)
}
or with a custom job id (for instance, to customize works execution order, or use a determistic id to avoid creating duplicate jobs):
const payload = { what: 'ever' }
try {
const jobId = 'abc123'
await queue.pushWithCustomJobId(jobId, payload))
} catch (err) {
console.error('Error pushing work into the queue', err.stack)
}
which can also be done in batch:
const payload = { what: 'ever' }
try {
const jobs = [
[ 'abc123', payload ],
[ 'efg456', payload ],
]
await queue.pushBatchWithCustomJobIds(jobs))
} catch (err) {
console.error('Error pushing work into the queue', err.stack)
}
(Only works for jobs that haven't started yet!)
try {
await queue.del(jobId)
} catch (err) {
console.error('Error deleting job', err.stack)
}
or in batch:
try {
await queue.delBatch(jobIds)
} catch (err) {
console.error('Error deleting jobs', err.stack)
}
By default, the worker received one job id and payload at a time, but it's also possible to execute jobs in batches:
async function batchWorker(jobEntries) {
await doSomething()
}
This function gets a single argument: jobEntries, which is an array of job ids and payloads tuples.
To use a batch worker, the queue batchLength option MUST be above 1. For example:
const queue = Jobs(db, batchWorker, {
batchLength: 50,
maxConcurrency: 5,
})
queue.pendingStream() emits queued jobs. queue.runningStream() emits currently running jobs.
const stream = queue.pendingStream()
stream.on('data', function (data) {
const jobId = data.key
const payload = data.value
console.log('pending job id: %s, payload: %j', jobId, payload)
})
A queue object emits the following event:
drain — when there are no more jobs pending. Also happens on startup after consuming the backlog work units.error - when something goes wrong.retry - when a job is retried because something goes wrong.If you simply want a pure queue client that is only able to push jobs into the queue, you can use level-jobs/client like this:
import QueueClient from 'level-jobs/client'
const client = QueueClient(db)
try {
await client.push(work)
console.log('pushed')
} catch (err) {
console.error('pushing failed', err)
}
MIT
FAQs
Job Queue in LevelDB
The npm package @inventaire/level-jobs receives a total of 1 weekly downloads. As such, @inventaire/level-jobs popularity was classified as not popular.
We found that @inventaire/level-jobs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Security News
arXiv now limits authors to two submissions a month as AI slop overwhelms moderators, delays good papers, and sparks debate over applying the limit to everyone.

Research
/Security News
A new GhostAction wave hits hundreds of GitHub repos, expanding CI/CD secret theft to cloud and AI credentials in source code and git history.

Research
/Security News
Tensorlake npm SDK version 0.5.144 was compromised in a ChainDrop / Shai-Hulud attack, delivering credential-stealing malware.