Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Job Queues
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Libraries
Go
Services
Job Queues
Commits
fafc34f8
Verified
Commit
fafc34f8
authored
1 year ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
fix: check scheduler parameter
#28
parent
a2bfa64b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
errors.go
+1
-0
1 addition, 0 deletions
errors.go
persistence.go
+32
-0
32 additions, 0 deletions
persistence.go
with
33 additions
and
0 deletions
errors.go
+
1
−
0
View file @
fafc34f8
...
@@ -45,4 +45,5 @@ var (
...
@@ -45,4 +45,5 @@ var (
ErrNoManager
=
fmt
.
Errorf
(
"no manager"
)
ErrNoManager
=
fmt
.
Errorf
(
"no manager"
)
ErrCannotLoadStatsFromDatabase
=
fmt
.
Errorf
(
"errors while loading stats from database"
)
ErrCannotLoadStatsFromDatabase
=
fmt
.
Errorf
(
"errors while loading stats from database"
)
ErrInvalidTime
=
fmt
.
Errorf
(
"invalid time"
)
ErrInvalidTime
=
fmt
.
Errorf
(
"invalid time"
)
ErrSchedulerMisconfiguration
=
fmt
.
Errorf
(
"scheduler misconfiguration"
)
)
)
This diff is collapsed.
Click to expand it.
persistence.go
+
32
−
0
View file @
fafc34f8
...
@@ -3,6 +3,7 @@ package jobqueue
...
@@ -3,6 +3,7 @@ package jobqueue
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"github.com/robfig/cron/v3"
"gopkg.in/yaml.v3"
"gopkg.in/yaml.v3"
"gorm.io/gorm"
"gorm.io/gorm"
"io"
"io"
...
@@ -253,9 +254,26 @@ func CreateJobAndSchedulerFromPersistence(jobImport JobPersistence, manager *Man
...
@@ -253,9 +254,26 @@ func CreateJobAndSchedulerFromPersistence(jobImport JobPersistence, manager *Man
var
scheduler
Scheduler
var
scheduler
Scheduler
switch
sType
{
switch
sType
{
case
"interval"
:
case
"interval"
:
if
jobImport
.
Scheduler
.
Interval
==
0
{
return
nil
,
nil
,
fmt
.
Errorf
(
"%w: interval is 0"
,
ErrSchedulerMisconfiguration
)
}
scheduler
=
&
IntervalScheduler
{
Interval
:
jobImport
.
Scheduler
.
Interval
}
scheduler
=
&
IntervalScheduler
{
Interval
:
jobImport
.
Scheduler
.
Interval
}
case
"cron"
:
case
"cron"
:
if
jobImport
.
Scheduler
.
Spec
==
""
{
return
nil
,
nil
,
fmt
.
Errorf
(
"%w: spec is empty"
,
ErrSchedulerMisconfiguration
)
}
// check spec
parser
:=
cron
.
NewParser
(
cron
.
Second
|
cron
.
Minute
|
cron
.
Hour
|
cron
.
Dom
|
cron
.
Month
|
cron
.
Dow
|
cron
.
Descriptor
)
_
,
err
:=
parser
.
Parse
(
jobImport
.
Scheduler
.
Spec
)
if
err
!=
nil
{
return
nil
,
nil
,
fmt
.
Errorf
(
"%w: %v"
,
ErrSchedulerMisconfiguration
,
err
)
}
scheduler
=
&
CronScheduler
{
scheduler
=
&
CronScheduler
{
Spec
:
jobImport
.
Scheduler
.
Spec
,
Spec
:
jobImport
.
Scheduler
.
Spec
,
}
}
...
@@ -266,14 +284,28 @@ func CreateJobAndSchedulerFromPersistence(jobImport JobPersistence, manager *Man
...
@@ -266,14 +284,28 @@ func CreateJobAndSchedulerFromPersistence(jobImport JobPersistence, manager *Man
case
"delay"
:
case
"delay"
:
if
jobImport
.
Scheduler
.
Delay
==
0
{
return
nil
,
nil
,
fmt
.
Errorf
(
"%w: delay is 0"
,
ErrSchedulerMisconfiguration
)
}
scheduler
=
&
DelayScheduler
{
Delay
:
jobImport
.
Scheduler
.
Delay
}
scheduler
=
&
DelayScheduler
{
Delay
:
jobImport
.
Scheduler
.
Delay
}
case
"event"
:
case
"event"
:
if
jobImport
.
Scheduler
.
Event
==
""
{
return
nil
,
nil
,
fmt
.
Errorf
(
"%w: event is empty"
,
ErrSchedulerMisconfiguration
)
}
scheduler
=
&
EventScheduler
{
Event
:
EventName
(
jobImport
.
Scheduler
.
Event
)}
scheduler
=
&
EventScheduler
{
Event
:
EventName
(
jobImport
.
Scheduler
.
Event
)}
case
"instant"
:
case
"instant"
:
scheduler
=
&
InstantScheduler
{}
scheduler
=
&
InstantScheduler
{}
case
"time"
:
case
"time"
:
if
jobImport
.
Scheduler
.
Time
==
nil
{
return
nil
,
nil
,
fmt
.
Errorf
(
"%w: time is nil"
,
ErrSchedulerMisconfiguration
)
}
scheduler
=
&
TimeScheduler
{
Time
:
*
jobImport
.
Scheduler
.
Time
}
scheduler
=
&
TimeScheduler
{
Time
:
*
jobImport
.
Scheduler
.
Time
}
default
:
default
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment