Article ID:360032822832
2 minute readKnowledge base
On this page

CloudBees CD (CloudBees Flow) provides big veriety of tools to manage your tasks and resources.

This article describes an approach for restricting work from being able to run during certain hours and a way to balance the load on your resources.


Following example contains a project that has a number of procedures that if ran during the day with other user activities can bring down the resource it’s using. We want users to be able to submit their jobs, but we don’t want jobs to run untill 6pm-6am (off hours).


A key understanding to recognize is that single server destination can have multiple resources created against it.

Also, it is important to understand that we can control the load by setting step limits.

We can choose to create a "commonResource" for use by the wider set of smaller tasks, where the step limit is set to some manageable number like 5-10, and then also have a "heavyResource" for the larger jobs where the step-limit is perhaps set to 1. This would ensure that no more than 1 "heavy" job is ever running at one time.

Whenever you request more steps than the limit definition, the system will simply queue those requests up until openings become available.

Now, we need to limit the "heavy tasks" to start at 6:00pm without submitters need to create their own schedules.

1. Designate the 2 types of resources.


2.Define a pool called "heavyPool" and designate the scripts that are the heavy procedures to use that pool rather than any given resource but don’t define any resourceNames for this pool as it’s starting point.


3. Create 2 schedules for the following simple operations:


3a To add the heavy_resource into the pool, run a job with following command at 6:00pm:

ectool addResourcesToPool --resourcePoolName heavyPool --resourceNames heavyResource
  • This essentially activates any jobs to start working with this resource

3b To empty the list of resources for this pool, run a job with following command at 6:00am:

ectool removeResourcesFromPool "heavyPool" --resourceNames "heavyResource"

This way, any further requests that come in during the day will simply queue up until the (3a ) is run again

  • This deactivates any jobs from running using this resource

  • This could leave a "heavy job" on the queue until the next day, so you may need to add something more complicated to manage that case if it came down to it.

4. Then you would want to have a "front-end step" in your heavy procedure that identifies the pool and marks the selected resource as job-level exclusive. but also stores the selected resource name into a job-run-time property and then have all other steps in the procedure reference this run-time property for the resource name directly.

"Front-end step":


Other steps:


This step will then wait until the moment a slot opens up in the pool, and once granted, the resource is essentially allocated to this job.

The use of exclusivity will lock the resource down to the job, but by referencing the resourcename via the property in all subsequent steps, rather than the pool name, you avoid the case where a heavy-job runs past 6:00am when the resource is no longer inside the pool, which would otherwise cause the steps to wait 12 hours to continue again at 6:00pm.