~rjarry/dlrepo

dlrepo: job: display upload time v1 NEEDS REVISION

Julien Floret: 1
 job: display upload time

 5 files changed, 35 insertions(+), 0 deletions(-)
#754983 .build.yml failed
Hi Olivier,

Olivier Matz, May 10, 2022 at 18:29:
Next
Le mar. 10 mai 2022 à 20:58, Robin Jarry <robin@jarry.cc> a écrit :
Next
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~rjarry/dlrepo/patches/32148/mbox | git am -3
Learn more about email & git

[PATCH dlrepo] job: display upload time Export this patch

Create a stamp file in the job folder when the first metadata is added
to the job.
Export the job upload time as an UTC formatted string in the
job metadata. We determine it by looking at the modification time
of the .stamp file (which is created inside the job folder when the
first metadata is added to the job).

The upload time is automatically displayed on the job web page as part
of the job metadata.
Signed-off-by: Julien Floret <julien.floret@6wind.com>
---
 dlrepo/fs/job.py           | 20 ++++++++++++++++++++
 dlrepo/fs/util.py          |  8 ++++++++
 dlrepo/views/job.py        |  3 +++
 docs/dlrepo-api.7.scdoc    |  1 +
 docs/dlrepo-layout.7.scdoc |  3 +++
 5 files changed, 35 insertions(+)

diff --git a/dlrepo/fs/job.py b/dlrepo/fs/job.py
index 3ab3a698eb49..78a429deb9b8 100644
--- a/dlrepo/fs/job.py
+++ b/dlrepo/fs/job.py
@@ -22,6 +22,26 @@ class Job(SubDir):
    TODO
    """

    def create(self):
        super().create()
        stamp = self._path / ".stamp"
        if not stamp.exists():
            stamp.touch()

    @classmethod
    def creation_date(cls, j):
        stamp = j.path() / ".stamp"
        if stamp.is_file():
            # prefer mtime over ctime
            # on UNIX, ctime is "the time of most recent metadata change" whereas
            # mtime is "most recent content modification"
            return stamp.stat().st_mtime
        return 0

    @property
    def timestamp(self) -> int:
        return Job.creation_date(self)

    def get_formats(self) -> Iterator[ArtifactFormat]:
        yield from ArtifactFormat.all(self)

diff --git a/dlrepo/fs/util.py b/dlrepo/fs/util.py
index dc61b083cfc5..c6703f1456b6 100644
--- a/dlrepo/fs/util.py
+++ b/dlrepo/fs/util.py
@@ -2,6 +2,7 @@
# Copyright (c) 2021 Robin Jarry
# SPDX-License-Identifier: BSD-3-Clause

from datetime import datetime, timezone
import hashlib
import os
from pathlib import Path
@@ -133,3 +134,10 @@ def human_readable(value):
    if value < 100:
        return f"{value:.1f}{unit}"
    return f"{value:.0f}{unit}"


# --------------------------------------------------------------------------------------
def utc_time(timestamp):
    return datetime.fromtimestamp(timestamp, tz=timezone.utc).strftime(
        "%a, %d %b %Y %H:%M:%S %Z"
    )
diff --git a/dlrepo/views/job.py b/dlrepo/views/job.py
index 16923c65e2b0..e2bf6f6a8c05 100644
--- a/dlrepo/views/job.py
+++ b/dlrepo/views/job.py
@@ -7,6 +7,7 @@ import asyncio
from aiohttp import web
import aiohttp_jinja2

from ..fs.util import utc_time
from .util import BaseView, TarResponse


@@ -68,6 +69,8 @@ class JobView(JobArchiveView):
        html = "html" in self.request.headers.get("Accept", "json")
        data = {"job": job.get_metadata()}
        data["job"]["internal"] = job.is_internal()
        if job.timestamp:
            data["job"]["upload_time"] = utc_time(job.timestamp)
        formats = []
        for f in job.get_formats():
            fmt_url = f.url()
diff --git a/docs/dlrepo-api.7.scdoc b/docs/dlrepo-api.7.scdoc
index 5ac9301852bd..6836dfad1577 100644
--- a/docs/dlrepo-api.7.scdoc
+++ b/docs/dlrepo-api.7.scdoc
@@ -313,6 +313,7 @@ Get metadata and artifact formats for the specified _{job}_.
			"name": "foobaz-x86_64-postgresql",
			"locked": true,
			"internal": false,
			"upload_time": "Mon, 09 May 2022 09:06:54 UTC",
			"product": "foobaz",
			"product_variant": "x86_64-postgresql",
			"product_branch": "3.2",
diff --git a/docs/dlrepo-layout.7.scdoc b/docs/dlrepo-layout.7.scdoc
index 8f80749f1f1e..47e21be946f1 100644
--- a/docs/dlrepo-layout.7.scdoc
+++ b/docs/dlrepo-layout.7.scdoc
@@ -112,6 +112,9 @@ _.metadata_ (optional)
		"baz": "bar"
	}
	```
_.stamp_
	Empty file created when the job is first created. This is used to
	display the job creation time.
_.locked_ (optional)
	Empty file created when the job is locked to avoid further
	modifications. A locked job cannot receive file uploads nor metadata
-- 
2.30.2
dlrepo/patches/.build.yml: FAILED in 28s

[job: display upload time][0] from [Julien Floret][1]

[0]: https://lists.sr.ht/~rjarry/dlrepo/patches/32148
[1]: mailto:julien.floret@6wind.com

✗ #754983 FAILED dlrepo/patches/.build.yml https://builds.sr.ht/~rjarry/job/754983
Le mar. 10 mai 2022 à 10:32, Julien Floret <julien.floret@6wind.com> a écrit :
Hi there,

Julien Floret, May 10, 2022 at 10:32: