Created
November 24, 2015 09:13
-
-
Save bmoussaud/c54c5810db4dd329833e to your computer and use it in GitHub Desktop.
XLDeploy: Check running tasks running or have scheduled to prevent several deployment on the same environment
This file contains 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
def deployedApplication(): | |
return specification.deployedOrPreviousApplication | |
environment = deployedApplication().environment | |
candidates = filter(lambda task: task.metadata['environment_id'] == environment.id, taskService.allCurrentTasks) | |
if len(candidates) == 1: | |
raise Exception("%d deployment task is running or has been scheduled on '%s'" % (len(candidates), environment.id)) | |
if len(candidates) > 1: | |
raise Exception("%d deployment tasks are running or have been scheduled on '%s'" % (len(candidates), environment.id)) | |
context.addStep(steps.jython( | |
description = "Check there is no running deployment tasks running on '%s' " % environment.id, | |
order = 60, | |
script_path = "task/step/check.py", | |
jython_context = {"environment_id": environment.id, | |
"application_name": deployedApplication().version.application.name, | |
"version_name": deployedApplication().version.name} | |
)) |
This file contains 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
print "Environment %s" % environment_id | |
print "Application %s" % application_name | |
print "Version %s" % version_name | |
def task_predicate(task): | |
metadata = task.metadata | |
return metadata['environment_id'] == environment_id and not (metadata['application'] == application_name and metadata['version'] == version_name) | |
candidates = filter(task_predicate, taskService.allCurrentTasks) | |
if len(candidates) == 1: | |
raise Exception("%d deployment task is running or has been scheduled on '%s'" % (len(candidates), environment_id)) | |
if len(candidates) > 1: | |
raise Exception("%d deployment tasks are running or have been scheduled on '%s'" % (len(candidates), environment_id)) | |
print "no running tasks on %s, go on...." % environment_id |
This file contains 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
<rule name="check.running.task.in.the.current.environment" scope="pre-plan"> | |
<planning-script-path>task/planning/check.py</planning-script-path> | |
</rule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment