Skip to content

Instantly share code, notes, and snippets.

@bmoussaud
Created November 24, 2015 09:13
Show Gist options
  • Save bmoussaud/c54c5810db4dd329833e to your computer and use it in GitHub Desktop.
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
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}
))
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
<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