Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substituting fixed delays with cron expression #234

Merged
merged 8 commits into from
Jul 14, 2023
Merged

Conversation

VithikaS
Copy link
Collaborator

@VithikaS VithikaS commented Jul 11, 2023

Description

Changed scheduling of tasks from using fixed delays to using cron expression.
This change will enable triggering of jobs on more calendar like events.

Addressed Issue

Part of work required to make api server highly available
DependencyTrack/hyades#375

Additional Details

Checklist

  • I have read and understand the contributing guidelines
  • This PR fixes a defect, and I have provided tests to verify that the fix is effective
  • This PR implements an enhancement, and I have provided tests to verify that it works as intended
  • This PR introduces changes to the database model, and I have added corresponding update logic
  • This PR introduces new or alters existing behavior, and I have updated the documentation accordingly

vithikashukla added 5 commits July 11, 2023 14:59
Signed-off-by: vithikashukla <[email protected]>
Signed-off-by: vithikashukla <[email protected]>
Signed-off-by: vithikashukla <[email protected]>
Copy link
Member

@nscuro nscuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @VithikaS, really like the simplicity of this! Looks good so far.


protected void scheduleTask(Map<Event, Schedule> eventScheduleMap) {
timer = new Timer();
timer.schedule(new ScheduleEvent().eventScheduleMap(eventScheduleMap), 100, 10000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make the delay configurable, and use a higher default value than 100?

Generally I think we should avoid scheduling any tasks while the API server is starting up, but the duration of the startup will of course vary depending on available resources etc.

Comment on lines 118 to 120
} catch (InvalidExpressionException invalidExpressionException) {
LOGGER.error("Exception in parsing cron expression and creating schedule", invalidExpressionException);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say we should just propagate the exception to the caller, or re-throw it as RuntimeException. Ideally, if a cron expression is invalid, we'd want the API server to not even start.

Comment on lines 370 to 384
task.cron.metrics.vulnerability=* 0/4 * * *
task.cron.mirror.github=* 0/4 * * *
task.cron.mirror.osv=* 0/4 * * *
task.cron.mirror.nist=* 0/4 * * *
task.cron.componentIdentification=* 0/6 * * *
task.cron.ldapSync=* 0/6 * * *
task.cron.vulndbSync=* 0/4 * * *
task.cron.repoMetaAnalysis=* 0/8 * * *
task.cron.vulnAnalysis=* 0/8 * * *
task.cron.vulnScanCleanUp=* 0/8 * * *
task.cron.fortify.ssc.sync=* 0/8 * * *
task.cron.defectdojo.sync=* 0/8 * * *
task.cron.kenna.sync=* 0/8 * * *
task.cron.index.consistency.check=* 0/8 * * *
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the default values we should add comments to explain what they are, as cron expressions can be quite cryptic if you're not used to them. For example, for task.cron.metrics.portfolio, add a comment saying Every 4 hours.

Copy link
Collaborator Author

@VithikaS VithikaS Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good comments.. going to address all of them in next commit. Thanks for the review!

Signed-off-by: vithikashukla <[email protected]>
@VithikaS VithikaS changed the title inital commit for parsing cron expression Substituting fixed delays with cron expression Jul 13, 2023
Signed-off-by: vithikashukla <[email protected]>
@VithikaS VithikaS marked this pull request as ready for review July 13, 2023 10:17
Signed-off-by: vithikashukla <[email protected]>
Copy link
Collaborator

@mehab mehab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@VithikaS VithikaS merged commit 86e9105 into main Jul 14, 2023
@VithikaS VithikaS deleted the parse-cron-expression branch July 14, 2023 16:25
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants