Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Ecolyo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
web-et-numerique
Factory
LLLE_Project
Ecolyo
Commits
c6c05929
Commit
c6c05929
authored
1 year ago
by
Rémi PAILHAREY
Browse files
Options
Downloads
Patches
Plain Diff
fix: randomize cron seconds for triggers
parent
6443703d
No related branches found
No related tags found
2 merge requests
!1062
2.7 Release
,
!1027
Grdf too many requests
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/services/fluidConfig.service.spec.ts
+13
-4
13 additions, 4 deletions
src/services/fluidConfig.service.spec.ts
src/services/fluidConfig.service.ts
+5
-4
5 additions, 4 deletions
src/services/fluidConfig.service.ts
src/services/triggers.service.ts
+1
-1
1 addition, 1 deletion
src/services/triggers.service.ts
with
19 additions
and
9 deletions
src/services/fluidConfig.service.spec.ts
+
13
−
4
View file @
c6c05929
...
...
@@ -9,11 +9,20 @@ describe('ConfigService service', () => {
})
})
describe
(
'
getCronArgs
'
,
()
=>
{
it
(
'
should return the args of a cron
'
,
()
=>
{
const
max
=
5
const
min
=
5
it
(
'
should return minimum cron
'
,
()
=>
{
const
min
=
7
const
max
=
9
jest
.
spyOn
(
global
.
Math
,
'
random
'
).
mockReturnValue
(
0
)
const
result
=
configService
.
getCronArgs
(
min
,
max
)
expect
(
typeof
result
).
toEqual
(
'
string
'
)
expect
(
result
).
toEqual
(
`0 0
${
min
}
* * *`
)
})
it
(
'
should return maximum cron
'
,
()
=>
{
const
min
=
7
const
max
=
9
jest
.
spyOn
(
global
.
Math
,
'
random
'
).
mockReturnValue
(
0.9999
)
const
result
=
configService
.
getCronArgs
(
min
,
max
)
expect
(
result
).
toEqual
(
`59 59
${
max
}
* * *`
)
})
})
})
This diff is collapsed.
Click to expand it.
src/services/fluidConfig.service.ts
+
5
−
4
View file @
c6c05929
...
...
@@ -7,13 +7,14 @@ export default class ConfigService {
}
/**
*
*
Generate a cron between min:00:00 and max:59:59
* @param min Minimum hour for cron
* @param max Maximum hour for cron
*/
public
getCronArgs
(
min
=
8
,
max
=
9
):
string
{
public
getCronArgs
(
min
:
number
,
max
:
number
):
string
{
const
randomHour
=
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
+
1
)
+
min
)
// NOSONAR
const
randomMinutes
=
Math
.
floor
(
Math
.
random
()
*
59
)
// NOSONAR
return
`0
${
randomMinutes
}
${
randomHour
}
* * *`
const
randomMinutes
=
Math
.
floor
(
Math
.
random
()
*
60
)
// NOSONAR
const
randomSeconds
=
Math
.
floor
(
Math
.
random
()
*
60
)
// NOSONAR
return
`
${
randomSeconds
}
${
randomMinutes
}
${
randomHour
}
* * *`
}
}
This diff is collapsed.
Click to expand it.
src/services/triggers.service.ts
+
1
−
1
View file @
c6c05929
...
...
@@ -25,7 +25,7 @@ export default class TriggerService {
private
createTriggerAttributes
(
account
:
Account
,
konnector
:
Konnector
)
{
const
configService
=
new
ConfigService
()
const
cronArgs
=
configService
.
getCronArgs
()
const
cronArgs
=
configService
.
getCronArgs
(
7
,
9
)
const
triggerAttributes
:
TriggerAttributes
=
buildAttributes
({
account
:
account
,
cron
:
cronArgs
,
...
...
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