Skip to content

Commit f5ec5e2

Browse files
committed
Feature: Allow default max jobs per server to be set at the group level (individual servers can override).
1 parent a98c557 commit f5ec5e2

4 files changed

Lines changed: 29 additions & 2 deletions

File tree

docs/api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,7 @@ Parameters (required fields):
16201620
|---------------|------|-------------|
16211621
| `title` | String | **(Required)** Visual name for the group. |
16221622
| `hostname_match` | String | **(Required)** A regular expression string used to auto-match servers to the group. |
1623+
| (Other) | Various | Any other [Group](data.md#group) fields (e.g. `title`, `hostname_match`, `icon`, `notes`, `alert_actions`). |
16231624

16241625
Example request:
16251626

@@ -3983,6 +3984,7 @@ Parameters:
39833984
| `icon` | String | Optional icon ID for the server, displayed in the UI. Icons are sourced from [Material Design Icons](https://materialdesignicons.com/).
39843985
| `groups` | Array | Optional set of [Group.id](data.md#group-id)s for the server. Only applicable if `autoGroup` is `false`. |
39853986
| `autoGroup` | Boolean | Optionally set the auto-group flag for the server (see below).
3987+
| `maxJobs` | Integer | Optionally limit the number of concurrent jobs allowed to run on the server. |
39863988
| (Other) | Various | Any other updatable [Server](data.md#server) fields. |
39873989

39883990
Special behavior:

docs/data.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,10 @@ An internal revision number for the group, incremented with each change.
574574

575575
An integer value representing the sort order of the group. Lower values are sorted first.
576576

577+
### Group.max_jobs_per_server
578+
579+
An optional default job concurrency limit to place on each server in the group. Set to `0` for infinite. Individual servers may override this via [Server.maxJobs](#server-maxjobs).
580+
577581
## Job
578582

579583
A job is a running (or previously ran) instance of an event. The job structure has nearly all the same properties as [Event](#event) with these differences:

htdocs/js/pages/admin/Groups.class.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,19 @@ Page.Groups = class Groups extends Page.ServerUtils {
471471
caption: 'Optionally enter a regular expression match to auto-include hostnames in the group.<br/>To match <b>all servers</b>, set this to <code>.+</code>'
472472
});
473473

474+
// max jobs per server
475+
html += this.getFormRow({
476+
label: 'Max Server Jobs:',
477+
content: this.getFormText({
478+
id: 'fe_eg_max_jobs_per_server',
479+
type: 'number',
480+
min: '0',
481+
step: '1',
482+
value: group.max_jobs_per_server || '0'
483+
}),
484+
caption: 'Optionally set a default for max concurrent jobs allowed to run on each server in the group. Set to `0` for unlimited. Note that individual servers may override this.'
485+
});
486+
474487
// actions
475488
// (requires this.actions to be populated)
476489
html += this.getFormRow({
@@ -500,6 +513,7 @@ Page.Groups = class Groups extends Page.ServerUtils {
500513
group.title = $('#fe_eg_title').val().trim();
501514
group.icon = $('#fe_eg_icon').val();
502515
group.hostname_match = $('#fe_eg_match').val();
516+
group.max_jobs_per_server = parseInt( $('#fe_eg_max_jobs_per_server').val() ) || 0;
503517
group.notes = $('#fe_eg_notes').val();
504518

505519
if (!group.title.length) {

lib/job.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,11 +813,18 @@ class Jobs {
813813

814814
filterServerByMaxJobs(server_id) {
815815
// filter server out of available set by optional maxJobs setting
816+
var self = this;
816817
var server = this.servers[server_id];
817-
if (!server.maxJobs) return true;
818+
var max_jobs = server.maxJobs || 0;
819+
820+
if (!max_jobs) (server.groups || []).forEach( function(group_id) {
821+
var group = Tools.findObject( self.groups, { id: group_id } );
822+
if (group && group.max_jobs_per_server && (!max_jobs || (group.max_jobs_per_server < max_jobs))) max_jobs = group.max_jobs_per_server;
823+
} );
824+
if (!max_jobs) return true;
818825

819826
var jobs = this.findActiveJobs({ server: server_id });
820-
return jobs.length < server.maxJobs;
827+
return jobs.length < max_jobs;
821828
}
822829

823830
checkAvailableJobServer(job) {

0 commit comments

Comments
 (0)