Repository: avocado-framework/avocado

Issue:
Improve Avocado jobs command
**Describe the bug**
A clear and concise description of what the bug is.

1. `avocado jobs list` returns unsorted list of job results. One improvement is to sort the list by `mtime`. This help find the recent jobs. 
2. `avocado jobs show` shows weird end time because we don't have the `end` attribute in the `results.json` any more. 

I have a fix on the first issue, but looking for inputs for the second one. One feasible fix is to replace the end time with the start time. 

**Steps to reproduce**
Steps to reproduce the behavior with a reproducible whenever possible.

```
# run a few tests
avocado run /bin/true
avocado run /bin/true
avocado run /bin/true
# 1. list
avocado jobs list
# 2. show
avocado jobs show
```

**Expected behavior**

1. 
```
b36e709ed01af2567e4df81842b678fb9dca51eb 2023-09-08 03:04:52.701753   1 (1/0/0/0)
11861a8dd228a86e7c0f2b3583fe6ca7011af99c 2023-09-08 03:00:01.887965   1 (1/0/0/0)
6a29261e8d23e963270c42c9147781fed3ca6118 2023-09-08 02:55:27.117886   1 (1/0/0/0)
```

2. 

```
JOB ID      : latest

Test ID     End Time            Run Time Status
1-/bin/true <correct time> 0.012107 PASS
```

**Current behavior**

1. 
```
b36e709ed01af2567e4df81842b678fb9dca51eb 2023-09-08 03:04:52.701753   1 (1/0/0/0)
6a29261e8d23e963270c42c9147781fed3ca6118 2023-09-08 02:55:27.117886   1 (1/0/0/0)
11861a8dd228a86e7c0f2b3583fe6ca7011af99c 2023-09-08 03:00:01.887965   1 (1/0/0/0)
```

2.
```
JOB ID      : latest

Test ID     End Time            Run Time Status
1-/bin/true 1970/01/01 01:51:03 01:51:03 0.012107 PASS
```

**System information (please complete the following information):**
 - OS: `Ubuntu 18.04.6 LTS`
 - Avocado version: `Avocado 102.0`
 - Avocado installation method: reproduce on github & pip installation




Discussion:
Hi @v1siuol, thank you for finding this and even start working on this. Any contribution is welcome. 

About the second issue, I think the best approach would be to compute the `end time` from `start time` and `time`. With such approach, we won't change the overall behavior.
@v1siuol  If you don't mind, I will assign this to you, since you're already working on the first problem.
Thanks! No problem, I am happy to work on it.

Resolving patch:
diff --git a/avocado/plugins/jobs.py b/avocado/plugins/jobs.py
--- a/avocado/plugins/jobs.py
+++ b/avocado/plugins/jobs.py
@@ -56,7 +56,8 @@ def _print_job_tests(tests):
         for test in tests:
             status = test.get("status")
             decorator = output.TEST_STATUS_DECORATOR_MAPPING.get(status)
-            end = datetime.fromtimestamp(test.get("end"))
+            # Retrieve "end" for backward compatibility
+            end = datetime.fromtimestamp(test.get("actual_end", test.get("end")))
             test_matrix.append(
                 (
                     test.get("id"),
@@ -174,7 +175,11 @@ def run(self, config):
         results = {}
 
         jobs_dir = get_logs_dir()
-        for result in glob(os.path.join(jobs_dir, "*/results.json")):
+        for result in sorted(
+            glob(os.path.join(jobs_dir, "*/results.json")),
+            key=os.path.getmtime,
+            reverse=True,
+        ):
             with open(result, "r", encoding="utf-8") as fp:
                 job = json.load(fp)
                 results[job["job_id"]] = result


Test patch: