Skip to content

Commit

Permalink
allow to start server externally (#225)
Browse files Browse the repository at this point in the history
This change allow a more flexible way to start Cuttle. You can now get only needed routes and bootstrap the server externally (to add some routes or custom behaviour)
  • Loading branch information
loicknuchel authored and Loïc Knuchel committed Feb 27, 2018
1 parent 0730ba4 commit fa66fe6
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions core/src/main/scala/com/criteo/cuttle/CuttleProject.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@ class CuttleProject[S <: Scheduling] private[cuttle] (

logger.info(s"Listening on http://localhost:$httpPort")
}

/**
* Connect to database and build routes. It allows you to start externally a server and decide when to start the scheduling.
*
* @param platforms The configured [[ExecutionPlatform ExecutionPlatforms]] to use to execute jobs.
* @param databaseConfig JDBC configuration for MySQL server 5.7.
* @param retryStrategy The strategy to use for execution retry. Default to exponential backoff.
*
* @return a tuple with cuttleRoutes (needed to start a server) and a function to start the scheduler
*/
def build(
platforms: Seq[ExecutionPlatform] = CuttleProject.defaultPlatforms,
databaseConfig: DatabaseConfig = DatabaseConfig.fromEnv,
retryStrategy: RetryStrategy = RetryStrategy.ExponentialBackoffRetryStrategy
): (Service, () => Unit) = {
val xa = Database.connect(databaseConfig)
val executor = new Executor[S](platforms, xa, logger, name)(retryStrategy)

val startScheduler = () => {
logger.info("Start workflow")
scheduler.start(workflow, executor, xa, logger)
}

(App(this, executor, xa).routes, startScheduler)
}
}

/**
Expand Down

0 comments on commit fa66fe6

Please sign in to comment.