Skip to content

Commit

Permalink
[split] Use a single exception type for invalid json, and ensure it i…
Browse files Browse the repository at this point in the history
…s handled in the Scheduler
  • Loading branch information
Stu Hood committed Apr 3, 2012
1 parent 3b6e417 commit 86afed6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ extends Process with JobConsumer {
job()
Stats.incr("job-success-count")
} catch {
case e: ShardBlackHoleException => Stats.incr("job-blackholed-count")
case e: ShardOfflineException =>
case _: ShardBlackHoleException =>
Stats.incr("job-blackholed-count")
case _: ShardOfflineException =>
Stats.incr("job-blocked-count")
errorQueue.put(job)
case e: BadJsonJobException =>
case _: UnparsableJsonException =>
badJobQueue.put(job)
Logger.get("bad_jobs").error(job.toString)
Stats.incr("job-bad-count")
Expand Down
10 changes: 4 additions & 6 deletions src/main/scala/com/twitter/gizzard/scheduler/JsonJob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import com.twitter.gizzard.proxy.LoggingProxy
import com.twitter.gizzard.util.Json


class UnparsableJsonException(s: String, cause: Throwable) extends Exception(s, cause)
class UnparsableJsonException(s: String, cause: Throwable) extends Exception(s, cause) {
def this(s: String) = this(s, null)
}

/**
* A Job that can encode itself as a json-formatted string. The encoding will be a single-element
Expand Down Expand Up @@ -83,18 +85,14 @@ class JsonNestedJobParser(codec: JsonCodec) extends JsonJobParser {
}
}

class BadJsonJobException(message: String, cause: Throwable) extends Exception(message, cause) {
def this(message: String) = this(message, null)
}

class BadJsonJob extends JsonJob {
errorCount = Integer.MAX_VALUE - 1
errorMessage = "Bad Job"
override def shouldReplicate = false
override def toMap: Map[String, Any] = Map()

override def apply() {
throw new BadJsonJobException("Bad job")
throw new UnparsableJsonException("Bad job")
}
}

Expand Down

0 comments on commit 86afed6

Please sign in to comment.