Skip to content

Commit

Permalink
feat(schedule): add name and allow disable
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Jun 30, 2024
1 parent aca9055 commit 8fe600f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
8 changes: 8 additions & 0 deletions api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,10 @@ definitions:
type: integer
template_id:
type: integer
name:
type: string
disabled:
type: boolean

Schedule:
type: object
Expand All @@ -786,6 +790,10 @@ definitions:
type: integer
template_id:
type: integer
name:
type: string
disabled:
type: boolean

ViewRequest:
type: object
Expand Down
13 changes: 8 additions & 5 deletions db/Schedule.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package db

type Schedule struct {
ID int `db:"id" json:"id"`
ProjectID int `db:"project_id" json:"project_id"`
TemplateID int `db:"template_id" json:"template_id"`
CronFormat string `db:"cron_format" json:"cron_format"`
RepositoryID *int `db:"repository_id" json:"repository_id"`
ID int `db:"id" json:"id"`
ProjectID int `db:"project_id" json:"project_id"`
TemplateID int `db:"template_id" json:"template_id"`
CronFormat string `db:"cron_format" json:"cron_format"`
Name string `db:"name" json:"name"`
Disabled bool `db:"disabled" json:"disabled"`

LastCommitHash *string `db:"last_commit_hash" json:"-"`
RepositoryID *int `db:"repository_id" json:"repository_id"`
}

type ScheduleWithTpl struct {
Expand Down
4 changes: 3 additions & 1 deletion db/sql/migrations/v2.10.11.sql
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
alter table `project__template` add `tasks` int not null default 0;
alter table `project__template` add `tasks` int not null default 0;
alter table `project__schedule` add `name` varchar(100);
alter table `project__schedule` add `disabled` boolean not null default false;
6 changes: 5 additions & 1 deletion services/schedules/SchedulePool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"strconv"
"sync"

log "github.com/sirupsen/logrus"
"github.com/ansible-semaphore/semaphore/db"
"github.com/ansible-semaphore/semaphore/db_lib"
"github.com/ansible-semaphore/semaphore/services/tasks"
"github.com/robfig/cron/v3"
log "github.com/sirupsen/logrus"
)

type ScheduleRunner struct {
Expand Down Expand Up @@ -111,6 +111,10 @@ func (p *SchedulePool) Refresh() {
p.locker.Lock()
p.clear()
for _, schedule := range schedules {
if schedule.Disabled {
continue
}

_, err := p.addRunner(ScheduleRunner{
projectID: schedule.ProjectID,
scheduleID: schedule.ID,
Expand Down

0 comments on commit 8fe600f

Please sign in to comment.