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

Add job start and end time #30

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

leewesleyv
Copy link

@leewesleyv leewesleyv commented Aug 30, 2024

Resolves #11

  • Add start and end time to job data for the Docker launcher
  • Add start and end time to job data for the K8s launcher
  • Add unit tests
  • Add documentation

@leewesleyv leewesleyv marked this pull request as draft August 30, 2024 06:55
@leewesleyv leewesleyv force-pushed the feature/11-job-start-and-end-time branch from 1df3848 to 0090c20 Compare August 30, 2024 07:03
@leewesleyv leewesleyv added the enhancement New feature or request label Aug 30, 2024
Copy link
Member

@wvengen wvengen left a comment

Choose a reason for hiding this comment

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

Nice!
Great to see some cleanup too (though some comments).
I still need to get used to the idea of introducing typing here. Maybe discuss this first at a standup, and then perhaps introduce later?

scrapyd_k8s/launcher/docker.py Outdated Show resolved Hide resolved
scrapyd_k8s/launcher/docker.py Show resolved Hide resolved
test_api.py Outdated
assert jobinfo['project'] == RUN_PROJECT
assert jobinfo['spider'] == RUN_SPIDER
assert jobinfo['state'] == 'finished'
assert datetime.strptime(jobinfo['start_time'], TIME_FORMAT)
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 rather keep the previous form, so that if anything is added to the dict, you are aware that a test needs changing.

Copy link
Author

Choose a reason for hiding this comment

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

I will update this. Would need to look a bit more into mocking the start_time and end_time of the jobs during tests, since a dict comparison will require the exact start_time and end_time of the container/pods. Or maybe a different solution.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, that makes sense.
What about removing the time fields from the dict under test, and testing these separately? That would both allow us to test the full response, and allow proper time comparison.
Or use a time-freezing testing library (there must exist one).

Copy link
Author

Choose a reason for hiding this comment

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

I tried using freezegun to set a specific time during testing, but since we are talking to the kubernetes/docker APIs and not using the datetime module, this solution did not work. I will do a bit more digging. The first solution should also work though, but it might be better to see if there are alternative solutions.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, that totally makes sense! I'm not for mocking the result in the component under test, so let's fix this in the testing part.

scrapyd_k8s/settings.py Outdated Show resolved Hide resolved
scrapyd_k8s/launcher/docker.py Outdated Show resolved Hide resolved
scrapyd_k8s/launcher/k8s.py Outdated Show resolved Hide resolved
Copy link
Member

@wvengen wvengen left a comment

Choose a reason for hiding this comment

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

Looking good, thanks!
I see you've added the first unit test. Great!
The API test is not a regular test, as it is meant to run against a running instance. I'm not really sure if it fits well into the general pytest infrastructure like this. What do you think?

I'd split the API tests (which can be run completely separate from scrapyd-k8s, and could even be run against a different implementation, iirc), and the unit tests, into separate CI jobs.

scrapyd_k8s/launcher/docker.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add start_time and end_time in listjobs.json
2 participants