diff --git a/README.md b/README.md index ac561b0..3581977 100644 --- a/README.md +++ b/README.md @@ -60,9 +60,12 @@ Request a resource ##### List of settings +* `url | {string}` [mandatory]: URL to crawl * `wait | {Number}`: Time to wait till request (default: 0) -* `headers | {{}}`: Default headers (default: {"User-Agent": "webcheck v1.0.0"}) +* `headers | {Object}`: Default headers (default: {"User-Agent": "webcheck v1.0.0"}) * `request | {request}`: The used request-module +* `immediately | {boolean}`: Should the crawl push as next one to queue. +* `parameters | {Object}`: A object to pass parameters to other plugins about this crawl ### Properties of webcheck @@ -85,6 +88,7 @@ All events emitted on the webcheck object. Webcheck emits the following events: +- `crawl` (request-settings): Emitted directly after calling crawl method. - `request` (request-settings): Emitted before request is executed. - `result` ({url, request-settings, request, response}): Emitted after middleware are executed and document is fetched - `drain`: Emitted on draining of queue diff --git a/index.js b/index.js index b31eabe..dd99bf3 100644 --- a/index.js +++ b/index.js @@ -149,9 +149,12 @@ Webcheck.prototype = { * @param {headers} [settings.headers] - Headers to use for this crawl (otherwise it uses the standard headers) * @param {number} [settings.wait] - Milliseconds to wait until queuing * @param {boolean} [settings.preventCrawl=false] - True if crawl should be prevented (works not async!) + * @param {boolean} [settings.immediately=false] - True if crawl should run immediately + * @param {*} [settings.parameters] - Parameters to pass for further processing * @param {Webcheck~queueCallback} cb - Callback for crawl * @returns {Webcheck} * @fires Webcheck#queue + * @fires Webcheck#crawl */ crawl: function crawlResource(settings, cb) { var caller; @@ -164,20 +167,30 @@ Webcheck.prototype = { settings.headers = settings.headers || this.headers; settings.preventCrawl = false; + /** + * @event Webcheck#crawl + * @type {Webcheck.crawlSettings} + */ + this.emit('crawl', settings); caller = function () { /** * @event Webcheck#queue - * @type {webcheck.crawlSettings} + * @type {Webcheck.crawlSettings} */ this.emit('queue', settings); if (settings.preventCrawl) { return cb(); } + if (settings.immediately) { + return this.queue.unshift(settings, cb); + + } /** * @callback Webcheck~queueCallback * @param {null|error} error - Throws error if there was one */ + this.queue.push(settings, cb); }.bind(this);