-
Notifications
You must be signed in to change notification settings - Fork 60
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
Add create schedule functionality to scheduler api #3353
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ammar92
reviewed
Aug 21, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work. Just a few remarks that might improve it even more. Can be QA'd
Checklist for QA:
What works:Seems to look good. Tested with the QA notes and also tested a migration scenario by going through the onboarding and then do an update to the schedule query. What doesn't work:n/a Bug or feature?:n/a |
underdarknl
approved these changes
Aug 22, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Adds the functionality of creating a schedule for an arbitrary task through the scheduler API. This functionality is needed for the upcoming recurring report tasks. It is necessary to specify at what interval this task needs to be executed for an individual report task. A schedule for a task can be created as follows:
Changes
models/schedule.py
computed field for deadline; we want to be able to calculate the deadline for the schedule when we create a schedule from the create endpoint. This allows the API client just to supply the cron expression and not do the deadline calculation itself.Update: a post init to calculate thedeadline_at
when it isn't supplied and a schedule is present did the job better with less code.server/
schedules.py
added create endpoint for schedules, adds validation ofdata
by referencing the scheduler withscheduler_id
, it also generates thehash
of the contents of thedata
field so this doesn't have to be done by the client.serializers/schedule.py
addingScheduleCreate
model to correctly serialize/validate the client request. Take note that issues are already created to tackle the server API like: Refactor scheduler rest api server #3162QA notes
We're going to create a
Schedule
through the newly created/schedules
endpoint:make reset
dev
. Don't start any scans though!curl -X POST -H "Content-Type: application/json" -d '{"scheduler_id": "boefje-dev", "schedule": "*/5 * * * *", "data": {"id": "12c3f698-5036-40ce-a1d5-1d59e50116d8", "boefje": { "id": "dns-records", "name": "DnsRecords", "version": null }, "input_ooi": "Hostname|internet|mispo.es", "dispatches": [], "organization": "dev" }}' http://localhost:8004/schedules
curl HTTP://localhost:8004/schedules
it should now list a scheduleCode Checklist
.env
changes files if required and changed the.env-dist
accordingly.Checklist for code reviewers:
Copy-paste the checklist from the docs/source/templates folder into your comment.
Checklist for QA:
Copy-paste the checklist from the docs/source/templates folder into your comment.