UNPKG

historical-deadletter-processor

Version:
96 lines (80 loc) 3.29 kB
"use strict"; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } // Generated by CoffeeScript 2.7.0 (function () { var AzureSearch, Promise, Repository, _, async, debug; _ = require("lodash"); Promise = require("bluebird"); debug = require("debug")("historical-deadletter:reader"); async = require("async"); AzureSearch = require("azure-search"); module.exports = Repository = function () { function Repository(opts) { _classCallCheck(this, Repository); var connection; connection = opts.connection; this.app = opts.app; this.job = opts.job; this.sender = opts.sender; var _opts$index = opts.index; this.index = _opts$index === undefined ? "errors" : _opts$index; this.nonRetryable = opts.nonRetryable; this.client = this._buildClient(connection); this.cargo = Promise.promisifyAll(this._buildCargo()); } _createClass(Repository, [{ key: "save", value: function save(doc) { debug("Saving doc with id %s", doc.id); return this.cargo.pushAsync(_.merge(doc, { timestamp: new Date() })); } }, { key: "search", value: function search(conditions, _ref) { var _ref$page = _ref.page, page = _ref$page === undefined ? 0 : _ref$page, _ref$size = _ref.size, size = _ref$size === undefined ? 100 : _ref$size; var queryOptions; queryOptions = { filter: conditions.join(" and "), skip: page * size, top: size }; debug("Searching errors %j", queryOptions); return this.client.searchAsync(this.index, queryOptions); } }, { key: "remove", value: function remove(ids) { debug("Removing ids %j", ids); return this.client.deleteDocumentsAsync(this.index, _.map(ids, function (id) { return { id: id }; })); } }, { key: "_buildClient", value: function _buildClient(_ref2) { var url = _ref2.url, key = _ref2.key; return Promise.promisifyAll(new AzureSearch({ url: url, key: key }), { multiArgs: true }); } }, { key: "_buildCargo", value: function _buildCargo() { var _this = this; return async.cargo(function (tasks, callback) { var documents; documents = _.uniqBy(tasks, 'id'); return _this.client.updateOrUploadDocumentsAsync(_this.index, documents).thenReturn().asCallback(callback); }); } }]); return Repository; }(); }).call(undefined);