Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 30 additions & 22 deletions src/fuzzfetch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,25 @@ def __init__(
now = datetime.now(timezone("UTC"))

try:
self._task = BuildTask(
build,
branch,
self._flags,
self._platform,
self._simulated,
)
self.resolve_targets(self._targets)
for obj in sorted(
BuildTask.iterall(
build,
branch,
self._flags,
platform=self._platform,
simulated=self._simulated,
),
reverse=True,
):
self._task = obj
with suppress(FetcherException):
self.resolve_targets(self._targets)
break
else:
raise FetcherException(
"Unable to find usable archive for "
f"{BuildTask._debug_str(build)}"
)
except FetcherException:
if not nearest:
raise
Expand Down Expand Up @@ -182,20 +193,17 @@ def __init__(
LOG.debug("trying %s", search_build)
# iterate over all builds for the day, and take the next
# older/newer build available
build_tasks = BuildTask.iterall(
search_build,
branch,
self._flags,
self._platform,
self._simulated,
)
if not asc:
build_tasks = reversed(list(build_tasks))

for task in build_tasks:
task_date = timezone("EST").localize(
datetime.fromtimestamp(task.rank)
)
for task in sorted(
BuildTask.iterall(
search_build,
branch,
self._flags,
self._platform,
self._simulated,
),
reverse=not asc,
):
task_date = task.rank_as_date
LOG.debug("got %s", task_date)
if (asc and task_date >= requested) or (
not asc and task_date <= requested
Expand Down
69 changes: 27 additions & 42 deletions src/fuzzfetch/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from dataclasses import dataclass, fields
from datetime import datetime
from enum import Enum
from functools import total_ordering
from itertools import chain, product
from logging import getLogger
from platform import machine as plat_machine
Expand Down Expand Up @@ -105,48 +106,16 @@ class BuildSearchOrder(Enum):
DESC = 2


@dataclass(eq=False, frozen=True)
@total_ordering
class BuildTask:
"""Class for storing TaskCluster build information"""

TASKCLUSTER_API = "https://firefox-ci-tc.services.mozilla.com/api/%s/v1"

def __init__(
self,
build: str | None,
branch: str | None,
flags: BuildFlags | None,
platform: Platform | None = None,
simulated: str | None = None,
_blank: bool = False,
) -> None:
"""Retrieve the task JSON object

Requires first generating the task URL based on the specified build type and
platform
"""
if _blank:
self.url: str | None = None
self.queue_server: str | None = None
self._data: dict[str, Any] = {}
return
assert build is not None
assert branch is not None
assert flags is not None
for obj in self.iterall(
build,
branch,
flags,
platform=platform,
simulated=simulated,
):
self.url = obj.url
self.queue_server = obj.queue_server
self._data = obj._data # pylint: disable=protected-access
break
else:
raise FetcherException(
f"Unable to find usable archive for {BuildTask._debug_str(build)}"
)
url: str
queue_server: str
_data: dict[str, Any]

@staticmethod
def _debug_str(build: str) -> str:
Expand Down Expand Up @@ -259,11 +228,7 @@ def generate_task_paths(
except RequestException:
continue

obj = cls(None, None, None, _blank=True)
obj.url = url
obj.queue_server = template % ("queue",)
obj._data = data.json() # pylint: disable=protected-access

obj = cls(url, template % ("queue",), data.json())
LOG.debug("Found archive for %s", cls._debug_str(build))
yield obj

Expand All @@ -274,6 +239,26 @@ def __getattr__(self, name: str) -> Any:
f"'{type(self).__name__}' object has no attribute '{name}'"
)

@property
def rank_as_date(self) -> datetime:
"""Return task rank as date object"""
result = timezone("EST").localize(datetime.fromtimestamp(self.rank))
assert isinstance(result, datetime)
return result

def __eq__(self, other: Any) -> bool:
if isinstance(other, BuildTask):
return self.rank_as_date == other.rank_as_date
return False

def __lt__(self, other: Any) -> bool:
if isinstance(other, BuildTask):
return self.rank_as_date < other.rank_as_date
raise TypeError(
"'<' not supported between instances of "
f"'{type(self).__name__}' and '{type(other).__name__}'"
)

@classmethod
def _pushdate_template_paths(
cls,
Expand Down
Loading