Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
api/ci.py: add flag to tell SQUAD not to fetch watched jobs right away
Browse files Browse the repository at this point in the history
This will be useful when submitting Tuxsuite builds and tests jobs that
are just started. It's useful to have them in SQUAD so that when results
start coming, the build will wait for all builds and tests results
before triggering events when it's finished.

Signed-off-by: Charles Oliveira <[email protected]>
  • Loading branch information
chaws committed Nov 10, 2023
1 parent 515df4a commit 498eba1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
6 changes: 4 additions & 2 deletions doc/ci.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ Submitting test job watch requests

Test job watch request are similar to test job requests. The only difference is
that some other service submitted the test job for execution and SQUAD is
requested to track the progress. After test job is finished SQUAD will retrieve
the results and do post processing. The API is following:
requested to track the progress. By default, SQUAD will schedule the job
for fetching right away. If the variable `?delay_fetch` is present, SQUAD will
wait until the test job is finished before retrieving the results and do post
processing. The API is following:

**POST** /api/watchjob/:group/:project/:build/:environment

Expand Down
6 changes: 4 additions & 2 deletions squad/api/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ def watch_job(request, group_slug, project_slug, version, environment_slug):

log_addition(request, test_job, "Watch Job submission")

# schedule a fetch task on this job right away
fetch.delay(test_job.id)
delay_fetch = request.GET.get("delay_fetch")
if delay_fetch is None:
# schedule a fetch task on this job right away
fetch.delay(test_job.id)

# return ID of test job
return HttpResponse(test_job.id, status=201)
Expand Down
35 changes: 35 additions & 0 deletions test/api/test_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,41 @@ def test_watch_testjob(self, fetch):
logentry_queryset.last().action_flag
)

@patch("squad.ci.tasks.fetch.delay")
def test_watch_testjob_do_not_fetch_rightaway(self, fetch):
testjob_id = 1234
args = {
'backend': 'lava',
'testjob_id': testjob_id,
}
r = self.client.post('/api/watchjob/mygroup/myproject/1/myenv?delay_fetch', args)
self.assertEqual(201, r.status_code)
testjob_queryset = models.TestJob.objects.filter(
target=self.project,
environment='myenv',
target_build=self.build,
backend=self.backend,
submitted=True,
job_id=testjob_id
)
self.assertEqual(
1,
testjob_queryset.count()
)
fetch.assert_not_called()
logentry_queryset = LogEntry.objects.filter(
user_id=self.project_privileged_user.pk,
object_id=testjob_queryset.last().pk
)
self.assertEqual(
1,
logentry_queryset.count()
)
self.assertEqual(
ADDITION,
logentry_queryset.last().action_flag
)

@patch("squad.ci.tasks.fetch.apply_async")
def test_watch_testjob_private_group(self, fetch):
testjob_id = 1234
Expand Down

0 comments on commit 498eba1

Please sign in to comment.