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() {
if (!this._providerConfig.enabled) return Promise.resolve();
return Promise.resolve(this._providerConfig.url)
.then(this._getListings.bind(this))
.then(this._normalize.bind(this))
.then(this._filter.bind(this))
.then(this._findNew.bind(this))
.then(this._storeStats.bind(this))
.then(this._save.bind(this))
.then(this._notify.bind(this))
.then(this._updateStates.bind(this))
.catch(this._handleError.bind(this));
return (
Promise.resolve(this._providerConfig.url)
//scraping the site and try finding new listings
.then(this._getListings.bind(this))
//bring them in a proper form (dictated by the provider)
.then(this._normalize.bind(this))
//filter listings with stuff tagged by the blacklist of the provider
.then(this._filter.bind(this))
//check if new listings available. if so proceed
.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) {
@@ -73,7 +82,6 @@ class FredyRuntime {
const newListings = listings.filter(o => getKnownListings(this._jobKey, this._providerId).indexOf(o.id) === -1);
if (newListings.length === 0) {
this._updateStates([]);
throw new NoNewListingsError();
}
@@ -85,10 +93,6 @@ class FredyRuntime {
return Promise.all(sendNotifications).then(() => newListings);
}
_updateStates(newListings) {
return newListings;
}
_save(newListings) {
setKnownListings(this._jobKey, this._providerId, [
...getKnownListings(this._jobKey, this._providerId),