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
09cc2019
Commit
09cc2019
authored
1 year ago
by
Rémi PAILHAREY
Browse files
Options
Downloads
Patches
Plain Diff
feat: randomize cron seconds for triggers
parent
a2c62ebb
No related branches found
No related tags found
1 merge request
!1027
Grdf too many requests
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/services/fluidConfig.service.spec.ts
+14
-4
14 additions, 4 deletions
src/services/fluidConfig.service.spec.ts
src/services/fluidConfig.service.ts
+9
-3
9 additions, 3 deletions
src/services/fluidConfig.service.ts
src/services/triggers.service.ts
+1
-1
1 addition, 1 deletion
src/services/triggers.service.ts
with
24 additions
and
8 deletions
src/services/fluidConfig.service.spec.ts
+
14
−
4
View file @
09cc2019
...
@@ -9,11 +9,21 @@ describe('ConfigService service', () => {
...
@@ -9,11 +9,21 @@ describe('ConfigService service', () => {
})
})
})
})
describe
(
'
getCronArgs
'
,
()
=>
{
describe
(
'
getCronArgs
'
,
()
=>
{
it
(
'
should return the args of a cron
'
,
()
=>
{
it
(
'
should return minimum cron
'
,
()
=>
{
const
max
=
5
const
min
=
7
const
min
=
5
const
max
=
9
jest
.
spyOn
(
configService
,
'
random
'
).
mockReturnValue
(
0
)
const
result
=
configService
.
getCronArgs
(
min
,
max
)
expect
(
result
).
toEqual
(
`0 0
${
min
}
* * *`
)
})
it
(
'
should return maximum cron
'
,
()
=>
{
const
min
=
7
const
max
=
9
jest
.
spyOn
(
configService
,
'
random
'
).
mockReturnValue
(
0.9999
)
const
result
=
configService
.
getCronArgs
(
min
,
max
)
const
result
=
configService
.
getCronArgs
(
min
,
max
)
expect
(
typeof
result
).
toEqual
(
'
string
'
)
expect
(
result
).
toEqual
(
`59 59
${
max
}
* * *`
)
})
})
})
})
})
})
This diff is collapsed.
Click to expand it.
src/services/fluidConfig.service.ts
+
9
−
3
View file @
09cc2019
...
@@ -6,14 +6,20 @@ export default class ConfigService {
...
@@ -6,14 +6,20 @@ export default class ConfigService {
return
Config
.
fluidConfig
as
FluidConfig
[]
return
Config
.
fluidConfig
as
FluidConfig
[]
}
}
// Wrapping Math.random for testing purposes
public
random
():
number
{
return
Math
.
random
()
}
/**
/**
*
*
* @param min Minimum hour for cron
* @param min Minimum hour for cron
* @param max Maximum hour for cron
* @param max Maximum hour for cron
*/
*/
public
getCronArgs
(
min
=
8
,
max
=
9
):
string
{
public
getCronArgs
(
min
=
8
,
max
=
9
):
string
{
const
randomHour
=
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
+
1
)
+
min
)
// NOSONAR
const
randomHour
=
Math
.
floor
(
this
.
random
()
*
(
max
-
min
+
1
)
+
min
)
// NOSONAR
const
randomMinutes
=
Math
.
floor
(
Math
.
random
()
*
59
)
// NOSONAR
const
randomMinutes
=
Math
.
floor
(
this
.
random
()
*
60
)
// NOSONAR
return
`0
${
randomMinutes
}
${
randomHour
}
* * *`
const
randomSeconds
=
Math
.
floor
(
this
.
random
()
*
60
)
// NOSONAR
return
`
${
randomSeconds
}
${
randomMinutes
}
${
randomHour
}
* * *`
}
}
}
}
This diff is collapsed.
Click to expand it.
src/services/triggers.service.ts
+
1
−
1
View file @
09cc2019
...
@@ -25,7 +25,7 @@ export default class TriggerService {
...
@@ -25,7 +25,7 @@ export default class TriggerService {
private
createTriggerAttributes
(
account
:
Account
,
konnector
:
Konnector
)
{
private
createTriggerAttributes
(
account
:
Account
,
konnector
:
Konnector
)
{
const
configService
=
new
ConfigService
()
const
configService
=
new
ConfigService
()
const
cronArgs
=
configService
.
getCronArgs
()
const
cronArgs
=
configService
.
getCronArgs
(
7
,
9
)
const
triggerAttributes
:
TriggerAttributes
=
buildAttributes
({
const
triggerAttributes
:
TriggerAttributes
=
buildAttributes
({
account
:
account
,
account
:
account
,
cron
:
cronArgs
,
cron
:
cronArgs
,
...
...
This diff is collapsed.
Click to expand it.
Rémi PAILHAREY
@rpailharey
mentioned in commit
262864a6
·
1 year ago
mentioned in commit
262864a6
mentioned in commit 262864a6d54146af19e8fd932c5c361efc2ec8c4
Toggle commit list
Rémi PAILHAREY
@rpailharey
mentioned in commit
3a0abc01
·
1 year ago
mentioned in commit
3a0abc01
mentioned in commit 3a0abc014606230e7b7d6483d94f3e5afef7cd6d
Toggle commit list
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