Socket
Socket
Sign inDemoInstall

couchdb-worker

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

couchdb-worker - npm Package Compare versions

Comparing version 0.4.5 to 0.5.0

86

lib/worker.js

@@ -29,2 +29,3 @@ /*

this.server_stripped = this.server.replace(/:\/\/.+:.+@/, '://');
this.auth = config.auth;

@@ -43,2 +44,3 @@ // processor

this.status_id = 'worker-status/' + this.name;
this.configDatabase = config.configDatabase || db;

@@ -59,11 +61,13 @@ // batch size defaults to 10

this.couch = request.defaults({
json: true,
auth: this.auth
});
console.log(this.name + ' worker listening on ' + this.server_stripped + '/' + this.db);
// initially get config
request({
url: this.server
+ '/' + encodeURIComponent(this.db)
+ '/' + encodeURIComponent(this.config_id),
json: true
}, function(error, resp, doc) {
this.couch.get(this.server
+ '/' + encodeURIComponent(this.configDatabase)
+ '/' + encodeURIComponent(this.config_id), function(error, resp, doc) {
if (error !== null) {

@@ -79,8 +83,5 @@ console.error(this.server_stripped + '/' + this.db + ' Error fetching config: ', error);

// initially get status
request({
url: this.server
+ '/' + encodeURIComponent(this.db)
+ '/' + encodeURIComponent(this.status_id),
json: true
}, function(error, resp, doc) {
this.couch.get(this.server
+ '/' + encodeURIComponent(this.configDatabase)
+ '/' + encodeURIComponent(this.status_id), function(error, resp, doc) {
if (error !== null) {

@@ -102,12 +103,14 @@ console.error(this.server_stripped + '/' + this.db + ' Error fetching status: ', error);

Worker.prototype._listen = function() {
request({
url: this.server
var url = this.server
+ '/' + encodeURIComponent(this.db)
+ '/_changes?include_docs=true&feed=longpoll'
+ '&timeout=' + this.timeout
+ '&limit=' + this.batch_size
// pick the highest seq we have: status.last_seq, since or last_seq
+ '&since=' + Math.max((this.status && this.status.last_seq) || 0, this.since || 0, this.last_seq || 0),
json: true
}, this._onchanges.bind(this));
+ '&limit=' + this.batch_size;
var since = (this.status && this.status.last_seq) || this.since || this.last_seq;
if (since) {
url += '&since=' + encodeURIComponent(since);
}
this.couch.get(url, this._onchanges.bind(this));
};

@@ -203,9 +206,6 @@

// save doc
request({
url: this.server
this.couch.put(this.server
+ '/' + encodeURIComponent(this.db)
+ '/' + encodeURIComponent(doc._id),
method: 'PUT',
body: JSON.stringify(doc),
json: true
+ '/' + encodeURIComponent(doc._id), {
body: JSON.stringify(doc)
}, function(error, resp, data) {

@@ -245,9 +245,6 @@ // ignore on errors, we will get this doc again as a change

// save doc
request({
url: this.server
this.couch.put(this.server
+ '/' + encodeURIComponent(this.db)
+ '/' + encodeURIComponent(doc._id),
method: 'PUT',
body: JSON.stringify(doc),
json: true
+ '/' + encodeURIComponent(doc._id), {
body: JSON.stringify(doc)
}, function(error, resp, data) {

@@ -269,8 +266,5 @@ // reset on errors

Worker.prototype._reset = function(doc) {
request({
url: this.server
this.couch.get(this.server
+ '/' + encodeURIComponent(this.db)
+ '/' + encodeURIComponent(doc._id),
json: true
}, function(error, resp, newDoc) {
+ '/' + encodeURIComponent(doc._id), function(error, resp, newDoc) {
// ignore on error

@@ -284,9 +278,6 @@ // TODO: retry on errors

// save doc
request({
url: this.server
this.couch.put(this.server
+ '/' + encodeURIComponent(this.db)
+ '/' + encodeURIComponent(doc._id),
method: 'PUT',
body: JSON.stringify(newDoc),
json: true
+ '/' + encodeURIComponent(doc._id), {
body: JSON.stringify(newDoc)
}, function(error, resp, data) {

@@ -334,9 +325,6 @@ // retry to reset on errors

// store status
request({
url: this.server
+ '/' + encodeURIComponent(this.db)
+ '/' + encodeURIComponent(this.status_id),
method: 'PUT',
body: JSON.stringify(this.status),
json: true
this.couch.put(this.server
+ '/' + encodeURIComponent(this.configDatabase)
+ '/' + encodeURIComponent(this.status_id), {
body: JSON.stringify(this.status)
}, function(error, resp, data) {

@@ -343,0 +331,0 @@ if (this._checkResponse(error, resp, data, 'store status')) return;

{
"name": "couchdb-worker",
"version": "0.4.5",
"version": "0.5.0",
"description": "This is an abstract CouchDB worker that manages worker status and handle attachment processing.",

@@ -5,0 +5,0 @@ "keywords": ["CouchDB", "couchdb-worker", "attachments", "worker", "abstract"],

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