Skip to content

Commit 7a2103a

Browse files
authored
feat: add flag 'allow parallel tasks' for template (#3151)
* feat: add flag 'allow parallel tasks' for template * chore(ui): add translation * feat(ui): add new label for parallel tasks checkbox
1 parent 7e14c7f commit 7a2103a

File tree

8 files changed

+24
-4
lines changed

8 files changed

+24
-4
lines changed

db/Migration.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func GetMigrations(dialect string) []Migration {
3030
{Version: "2.15.3"},
3131
{Version: "2.15.4"},
3232
{Version: "2.16.0"},
33+
{Version: "2.16.1"},
3334
}
3435
}
3536

@@ -109,6 +110,7 @@ func GetMigrations(dialect string) []Migration {
109110
{Version: "2.15.3"},
110111
{Version: "2.15.4"},
111112
{Version: "2.16.0"},
113+
{Version: "2.16.1"},
112114
}
113115
}
114116

db/Template.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ type Template struct {
157157
RunnerTag *string `db:"runner_tag" json:"runner_tag,omitempty"`
158158

159159
AllowOverrideBranchInTask bool `db:"allow_override_branch_in_task" json:"allow_override_branch_in_task,omitempty"`
160+
AllowParallelTasks bool `db:"allow_parallel_tasks" json:"allow_parallel_tasks,omitempty"`
160161
}
161162

162163
func (tpl *Template) FillParams(target any) error {

db/sql/migrations/v2.16.1.err.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table project__template drop column allow_parallel_tasks;

db/sql/migrations/v2.16.1.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alter table project__template add allow_parallel_tasks boolean not null default false;

db/sql/template.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ func (d *SqlDb) CreateTemplate(template db.Template) (newTemplate db.Template, e
2121
"playbook, arguments, allow_override_args_in_task, description, `type`, "+
2222
"start_version, build_template_id, view_id, autorun, survey_vars, "+
2323
"suppress_success_alerts, app, git_branch, runner_tag, task_params, "+
24-
"allow_override_branch_in_task)"+
24+
"allow_override_branch_in_task, allow_parallel_tasks)"+
2525
"values ("+
2626
"?, ?, ?, ?, ?, "+
2727
"?, ?, ?, ?, ?, "+
2828
"?, ?, ?, ?, ?, "+
2929
"?, ?, ?, ?, ?,"+
30-
"?)",
30+
"?, ?)",
3131
template.ProjectID,
3232
template.InventoryID,
3333
template.RepositoryID,
@@ -53,6 +53,7 @@ func (d *SqlDb) CreateTemplate(template db.Template) (newTemplate db.Template, e
5353
template.TaskParams,
5454

5555
template.AllowOverrideBranchInTask,
56+
template.AllowParallelTasks,
5657
)
5758

5859
if err != nil {
@@ -103,7 +104,8 @@ func (d *SqlDb) UpdateTemplate(template db.Template) error {
103104
"`git_branch`=?, "+
104105
"task_params=?, "+
105106
"runner_tag=?, "+
106-
"allow_override_branch_in_task=? "+
107+
"allow_override_branch_in_task=?, "+
108+
"allow_parallel_tasks=? "+
107109
"where id=? and project_id=?",
108110
template.InventoryID,
109111
template.RepositoryID,
@@ -125,6 +127,7 @@ func (d *SqlDb) UpdateTemplate(template db.Template) error {
125127
template.TaskParams,
126128
template.RunnerTag,
127129
template.AllowOverrideBranchInTask,
130+
template.AllowParallelTasks,
128131

129132
template.ID,
130133
template.ProjectID,
@@ -186,6 +189,7 @@ func (d *SqlDb) GetTemplates(projectID int, filter db.TemplateFilter, params db.
186189
"pt.runner_tag",
187190
"pt.task_params",
188191
"pt.allow_override_branch_in_task",
192+
"pt.allow_parallel_tasks",
189193
"(SELECT `id` FROM `task` WHERE template_id = pt.id ORDER BY `id` DESC LIMIT 1) last_task_id").
190194
From("project__template pt")
191195

services/tasks/TaskPool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (p *TaskPool) blocks(t *TaskRunner) bool {
290290
if r.Task.Status.IsFinished() {
291291
continue
292292
}
293-
if r.Template.ID == t.Task.TemplateID {
293+
if r.Template.ID == t.Task.TemplateID && !r.Template.AllowParallelTasks {
294294
return true
295295
}
296296
}

web/src/components/TemplateForm.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,16 @@
292292
@change="setSurveyVars"
293293
/>
294294

295+
<v-checkbox
296+
class="mt-0"
297+
v-model="item.allow_parallel_tasks"
298+
>
299+
<template v-slot:label>
300+
{{ $t('allow_parallel_tasks') }}
301+
<v-chip class="ml-2" small color="error">New</v-chip>
302+
</template>
303+
</v-checkbox>
304+
295305
<v-checkbox
296306
class="mt-0"
297307
:label="$t('iWantToRunATaskByTheCronOnlyForForNewCommitsOfSome')"

web/src/lang/en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ export default {
341341
limit: 'Limit',
342342

343343
runner_tag: 'Runner tag',
344+
allow_parallel_tasks: 'Allow parallel tasks',
344345
task_prompts: 'Prompts',
345346
template_advanced: 'Advanced options',
346347
template_app_options: '{app} options',

0 commit comments

Comments
 (0)