Skip to content

Commit

Permalink
publisher.pull: emit prepul and postpull messages in pull()
Browse files Browse the repository at this point in the history
Instead of prepull being in pull and postpull being in _update_metadata.
  • Loading branch information
enku committed Feb 11, 2024
1 parent 964a18d commit 8e11e42
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/gentoo_build_publisher/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,22 @@ def pull(
for tag in tags or []:
self.tag(build, tag)

self._update_build_metadata(record)
record, packages, gbp_metadata = self._update_build_metadata(record)

dispatcher.emit(
"postpull", build=record, packages=packages, gbp_metadata=gbp_metadata
)

return True

def _update_build_metadata(self, record: BuildRecord) -> None:
def _update_build_metadata(
self, record: BuildRecord
) -> tuple[BuildRecord, list[Package] | None, GBPMetadata | None]:
packages: list[Package] | None = None
gbp_metadata: GBPMetadata | None = None
jenkins_metadata = self.jenkins.get_metadata(record)
built = utctime(datetime.utcfromtimestamp(jenkins_metadata.timestamp / 1000))
logs = self.jenkins.get_logs(record)

record = self.records.save(record, logs=logs, completed=utctime(), built=built)

try:
Expand All @@ -174,11 +179,7 @@ def _update_build_metadata(self, record: BuildRecord) -> None:
gbp_metadata = self.gbp_metadata(jenkins_metadata, packages)
self.storage.set_metadata(record, gbp_metadata)

# We emit postpull here instead of in self.pull() because this has all the
# updated Build information
dispatcher.emit(
"postpull", build=record, packages=packages, gbp_metadata=gbp_metadata
)
return record, packages, gbp_metadata

def pulled(self, build: Build) -> bool:
"""Return true if the Build has been pulled"""
Expand Down
5 changes: 4 additions & 1 deletion tests/test_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ def test_pulled_when_storage_is_ok_but_db_is_not(self) -> None:
# On rare occasion (server crash) the build appears to be extracted but the
# record.completed field is None. In this case Publisher.pulled(build) should
# be False
with mock.patch.object(self.publisher, "_update_build_metadata"):
with mock.patch.object(
self.publisher, "_update_build_metadata"
) as update_build_metadata:
# _update_build_metadata sets the completed attribute
update_build_metadata.return_value = None, None, None # dummy values
self.publisher.pull(self.build)

self.assertFalse(self.publisher.pulled(self.build))
Expand Down

0 comments on commit 8e11e42

Please sign in to comment.