Last active
December 13, 2016 17:56
-
-
Save velvia/ff54ecd9bf352fa462d1bbf0fbcd74ee to your computer and use it in GitHub Desktop.
SCarman's spark job API on top of existing API
This file contains hidden or 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
package spark.jobserver.api | |
import com.typesafe.config.Config | |
import org.scalactic._ | |
import spark.jobserver.api._ | |
trait ContextProvider[C] { | |
val ctx: C with ContextLike = null | |
def context: C with ContextLike = ctx | |
} | |
trait SimpleSparkJob[R, CX] { | |
type JobOutput = R | |
type JobData = Config | |
type C = CX | |
def runJob(runtime: JobEnvironment, data: Config): R | |
def validate(runtime: JobEnvironment, config: Config): Config | |
val baseSparkJob = new SparkJobBase with ContextProvider[CX] { | |
def runJob(sc: C, runtime: JobEnvironment, data: JobData): JobOutput = { | |
ctx = sc | |
runJob(runtime, data) | |
} | |
def validate(sc: C, runtime: JobEnvironment, config: Config): JobData Or Every[ValidationProblem] = { | |
try { | |
Good(validate(runtime, config)) | |
} catch { | |
case e: Exception => Bad(SingleProblem(e.getMessage)) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment