This repository has been archived by the owner on May 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from FarmLogs/uncaught-exceptions
Implement uncaught exception handling in dispatcher.
- Loading branch information
Showing
4 changed files
with
31 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
(defproject com.farmlogs/dispatcher "1.0.0" | ||
(defproject com.farmlogs/dispatcher "1.0.1" | ||
:description "Library to start specific workers in a jar" | ||
:min-lein-version "2.0.0" | ||
:plugins [[s3-wagon-private "1.2.0"]] | ||
:repositories {"farmlogs-internal" {:url "s3p://fl-maven-repo/mvn" | ||
:username ~(System/getenv "AMAZON_KEY") | ||
:passphrase ~(System/getenv "AMAZON_SECRET")}} | ||
:dependencies [[org.clojure/clojure "1.6.0"]] | ||
:dependencies [[org.clojure/clojure "1.6.0"] | ||
[org.clojure/tools.logging "0.3.1"]] | ||
:main dispatcher.core | ||
:profiles {:uberjar {:aot :all}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(ns dispatcher.exceptions.protocols) | ||
|
||
(defprotocol HandleException | ||
"This protocol is an extension point enabling services to define | ||
behavior specific to a particular exception type when it's caught by | ||
the uncaught exception handler." | ||
(handle [exception thread])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
(ns dispatcher.exceptions.uncaught | ||
(:require [clojure.tools.logging :as log] | ||
[dispatcher.exceptions.protocols :as p])) | ||
|
||
;; Define default behavior for all exceptions. This can be overridden | ||
;; by downstream code. It can also be extended to more specific types. | ||
(extend-protocol p/HandleException | ||
Throwable | ||
(handle [exception thread] | ||
(log/error exception "Uncaught error on thread:" (.getName thread)))) | ||
|
||
(defn register-uncaught-exception-handler | ||
([] | ||
(Thread/setDefaultUncaughtExceptionHandler | ||
(reify Thread$UncaughtExceptionHandler | ||
(uncaughtException [_ thread throwable] | ||
(p/handle throwable thread)))))) |