Skip to content

Commit

Permalink
Handle errors from npm-registry-follow better
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Victor Bjelkholm <git@victor.earth>
  • Loading branch information
victorb committed May 20, 2019
1 parent fb8434c commit 97631b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion project.clj
Expand Up @@ -9,7 +9,7 @@
[ring/ring-devel "1.7.1"]
[compojure "1.6.1"]
[open-services/ipfs-api "1.1.0"]
[open-services/npm-registry-follow "1.1.0"]
[open-services/npm-registry-follow "1.2.1"]
[io.prometheus/simpleclient_hotspot "0.6.0"]
[org.clojure/data.json "0.2.6"]
[iapetos "0.1.8"]
Expand Down
28 changes: 17 additions & 11 deletions src/open_registry/core.clj
Expand Up @@ -14,18 +14,24 @@
(uncaughtException [_ thread ex]
(log/error ex "Uncaught exception on" (.getName thread))))))

(defn handle-change-error [ex]
(log/error ex))

(defn handle-change [package-name]
(let [path (format "/npmjs.org/%s/metadata.json" package-name)
exists? (path-exists? http/api-multiaddr path)]
(log/infof "[received update] %s" package-name)
(when exists?
;; TODO seems sometimes npm are not up-to-date with their own registry
;; as too quick requests can give us old information, even though the
;; replication server told us there was a change
(http/metadata-handler package-name true))
(if exists?
(future (metrics/increase :app/change-feed-update))
(future (metrics/increase :app/change-feed-skip)))))
(if (:error? package-name)
(handle-change-error (:exception package-name))
;; handle error
(let [path (format "/npmjs.org/%s/metadata.json" package-name)
exists? (path-exists? http/api-multiaddr path)]
(log/infof "[received update] %s" package-name)
(when exists?
;; TODO seems sometimes npm are not up-to-date with their own registry
;; as too quick requests can give us old information, even though the
;; replication server told us there was a change
(http/metadata-handler package-name true))
(if exists?
(future (metrics/increase :app/change-feed-update))
(future (metrics/increase :app/change-feed-skip))))))

;; Listens for changes to the npm registry and updates the metadata for
;; packages that already exists in our cache
Expand Down

0 comments on commit 97631b7

Please sign in to comment.