Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Scheduled Tasks

rjrudin edited this page Mar 5, 2019 · 9 revisions

This page has been started for the 3.10.0 release and will eventually document as many of the features as possible specific to deploying scheduled tasks.

Deploying multiple tasks with the same task-path

Release 3.10.0 introduces support for deploying multiple scheduled tasks with the same task-path. ml-app-deployer now uses both the task-path and the task-database properties to determine if a task has already been deployed. The thought behind this is that it is very unlikely to want to run the same scheduled task against the database, but at different times. If you do have a need to do so, please create an issue to explain your use case. As a workaround, you can create two separate scheduled task modules that invoke the same library function.

Referring to host names in scheduled task files

The Manage API for creating a scheduled task accepts a property named "task-host", which must be a host name. But you rarely want to hardcode this, as those names are likely to change across environments.

Support for doing this more easily will soon arrive in a new version of ml-gradle/ml-app-deployer, but in the mean time, you can use a script like one below to fetch the host names and set them as tokens that can be replaced in payload files (this particular script assumes there are at most 3 hosts; you can of course customize this to support any number of hosts).

task setHostTokens {
	doLast {
		def manageConfig = new com.marklogic.mgmt.ManageConfig(mlHost, 8002, mlUsername, mlPassword)
		def hostManager = new com.marklogic.mgmt.resource.hosts.HostManager(new com.marklogic.mgmt.ManageClient(manageConfig));

		hostManager.getHostNames().eachWithIndex { hostName, index ->
			mlAppConfig.customTokens.put("%%mlHostName" + index + "%%", hostName)
		}

		println "First host: " + mlAppConfig.customTokens.get("%%mlHostName0%%")
	}
}
mlDeployApp.dependsOn setHostTokens
mlDeployTasks.dependsOn setHostTokens

You can then reference the token in a scheduled task file like this:

"task-host": "%%mlHostName0%%"

Note there's nothing special about the "%%" delimiters, they're just a default way of making tokens more obvious and less susceptible to being replaced by accident.

Clone this wiki locally