Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create server outside of cuttle #225

Merged
merged 1 commit into from
Feb 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -49,6 +49,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 = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to expose that again. It is already available to user code.

logger.info("Start workflow")
scheduler.start(workflow, executor, xa, logger)
}

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

/**
Expand Down