some smaller improvements

This commit is contained in:
Christian Kellner
2020-02-26 18:20:41 +01:00
parent 6de8d6f01d
commit 7a8db3a990

View File

@@ -27,16 +27,25 @@ class FredyRuntime {
execute() { execute() {
if (!this._providerConfig.enabled) return Promise.resolve(); if (!this._providerConfig.enabled) return Promise.resolve();
return Promise.resolve(this._providerConfig.url) return (
.then(this._getListings.bind(this)) Promise.resolve(this._providerConfig.url)
.then(this._normalize.bind(this)) //scraping the site and try finding new listings
.then(this._filter.bind(this)) .then(this._getListings.bind(this))
.then(this._findNew.bind(this)) //bring them in a proper form (dictated by the provider)
.then(this._storeStats.bind(this)) .then(this._normalize.bind(this))
.then(this._save.bind(this)) //filter listings with stuff tagged by the blacklist of the provider
.then(this._notify.bind(this)) .then(this._filter.bind(this))
.then(this._updateStates.bind(this)) //check if new listings available. if so proceed
.catch(this._handleError.bind(this)); .then(this._findNew.bind(this))
//store update of number of found listings
.then(this._storeStats.bind(this))
//store everything in db
.then(this._save.bind(this))
//notify the user using the configured notification adapter
.then(this._notify.bind(this))
//if an error occurred on the way, handle it here.
.catch(this._handleError.bind(this))
);
} }
_getListings(url) { _getListings(url) {
@@ -73,7 +82,6 @@ class FredyRuntime {
const newListings = listings.filter(o => getKnownListings(this._jobKey, this._providerId).indexOf(o.id) === -1); const newListings = listings.filter(o => getKnownListings(this._jobKey, this._providerId).indexOf(o.id) === -1);
if (newListings.length === 0) { if (newListings.length === 0) {
this._updateStates([]);
throw new NoNewListingsError(); throw new NoNewListingsError();
} }
@@ -85,10 +93,6 @@ class FredyRuntime {
return Promise.all(sendNotifications).then(() => newListings); return Promise.all(sendNotifications).then(() => newListings);
} }
_updateStates(newListings) {
return newListings;
}
_save(newListings) { _save(newListings) {
setKnownListings(this._jobKey, this._providerId, [ setKnownListings(this._jobKey, this._providerId, [
...getKnownListings(this._jobKey, this._providerId), ...getKnownListings(this._jobKey, this._providerId),