Skip to content

Commit

Permalink
#43, #44, #45: Add crawl event, immediately and parameters option
Browse files Browse the repository at this point in the history
  • Loading branch information
atd-schubert committed Sep 18, 2015
1 parent 025f3f6 commit 441ecbd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -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

Expand All @@ -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
Expand Down
15 changes: 14 additions & 1 deletion index.js
Expand Up @@ -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;
Expand All @@ -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);

Expand Down

0 comments on commit 441ecbd

Please sign in to comment.