
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
couchdb-worker
Advanced tools
A worker module that manages state.
npm install couchdb-worker
Define an object with two functions: check and process:
var processor = {
check: function(doc) {
return true
},
process: function(doc, done) {
// do something with the doc
var output = {
foo: 'bar'
};
done(null, output);
}
}
The check function is called to decide whether this doc should be processed generally. For example you might only be interested in docs of a certain field. This function is the same as a filter function.
The processing takes place in the process function.
This function takes two arguments: the doc and a callback function, done,
which takes an error and the ouput of the processing when the job has been done.
This output will be merged with the doc (if error is null
) and saved.
Note that the doc could have been changed after the job has been started
so that the doc variable could differ from the doc when it gets saved.
The processor above inserts the property foo with the value bar into every document.
Also take a look at examples/.
Configuration is done in a worker configuration document inside the target database. The worker looks at all databases and only process if there exists such a configuration file.
A Worker Configuration File might look like this:
{
"_id": "worker-config/myworker",
"_rev": "1-a653b27246b01cf9204fa9f5dee7cc64",
"my_worker_setting": "100%"
}
You can update the config live so that all future processings will take the new configuration.
The worker stores a status document inside the target database. The worker stores its last update seq here and can resume at the point it has started the last processing.
{
"_id": "worker-status/myworker",
"_rev": "543-1922b5623d07453a753ab6ab2c634d04",
"last_seq": 34176,
"docs_processed": 145
}
The worker updates a status object inside the document. This makes it supereasy to monitor worker status as well as it keeps a lock when many workers listen to the same database.
The status object of the worker could look like this:
"worker_status": {
"worker-name": {
"status": "completed"
}
}
The status field can be triggered, completed or error.
The worker status is scoped by the worker name in order to have many workers processing the same document.
To start, this needs either the following environment variables set:
export HOODIE_SERVER=http://example.org
npm start
or pass them to the commandline:
HOODIE_SERVER=http://example.org npm start
Testing is done with Mocha. Run the tests with
npm test
(c) 2012 Johannes J. Schmidt, Berlin
Licensed under the Apache License 2.0.
FAQs
CouchDB worker module that manages state
The npm package couchdb-worker receives a total of 11 weekly downloads. As such, couchdb-worker popularity was classified as not popular.
We found that couchdb-worker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.