View Source

h1. Situation
Some grid nodes may have limited resource, and can only run limited number of concurrent jobs.

h1. Demonstration
[Project1|http://demo.pmease.com/dashboard/76], [project2|http://demo.pmease.com/dashboard/77], and [project3|http://demo.pmease.com/dashboard/78] are used to demonstrate the case where server node only permits to run two concurrent jobs.
# Trigger project1
# Trigger project2 right after you triggered project1, without waiting for its finish.
# Trigger project3 right after you triggered project2, without waiting for its finish.
# Switch to build log of these three configurations. You will see that project1 and project2 are actually doing the job (printing the message _do my job with acquired resource..._), while project3 is waiting for the resource (printing the message _Executing pre-execute script..._).
# After project1 or project2 finishes (in about 1 minute), project3 will acquire the resource and do the job.

h1. Resolution
Switch to [master step definition|http://demo.pmease.com/settings/75/steps] of these three projects:
# the pre-execute action is defined as:
{code}
groovy:
node.getResource("resource1", new java.util.concurrent.Semaphore(2)).acquire();
{code}
This tells QuickBuild to get node resource named _resource1_, and create the resource as a Java semaphore object with two permits if it does not already exist. And then acquire the resource by calling its _acquire_ method before executing the step.
# the post-execute action is defined as:
{code}
groovy:node.getResource("resource1").release();
{code}
This tells QuickBuild to release the node resource named _resource1_ before finishing the step.