Skip to content

Commit 9e75978

Browse files
committed
tools: improve api events example
Add cmdline arg option for node kind and document the API parameters a bit. Signed-off-by: Gustavo Padovan <[email protected]>
1 parent e60ed54 commit 9e75978

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

tools/example_api_events.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
It will filter only completed kernel builds, limit to 100 events per request,
66
and retrieve corresponding nodes with artifacts.
77
"""
8+
import argparse
89
import requests
910
import json
1011
import sys
@@ -20,8 +21,28 @@
2021
# saving last processed timestamp to a file or database
2122
timestamp = "1970-01-01T00:00:00.000000"
2223

23-
def pollevents(timestamp):
24-
url = BASE_URI + EVENTS_PATH + f"?kind=kbuild&state=done&limit=100&recursive=true&from={timestamp}"
24+
25+
"""
26+
kind:
27+
28+
There are a few different kinds:
29+
30+
* checkout: a new git tree checkout to be tested. Maestro frequently cuts
31+
new tree checkout from tree it is subscribed to. See 'config/pipeline.yaml'
32+
* kbuild: a new kernel build for a given config and arch
33+
* job: the execution of a test suite
34+
* test: the execution of a test inside a job
35+
36+
37+
state:
38+
39+
In this example we track state=done to get an event when Maestro is ready to
40+
provide all the information about the node. Eg for checkout it will provide
41+
the commit hash to test and for builds the location of the kernel binaries built.
42+
"""
43+
44+
def pollevents(timestamp, kind):
45+
url = BASE_URI + EVENTS_PATH + f"?state=done&kind={kind}&limit=100&recursive=true&from={timestamp}"
2546
print(url)
2647
response = requests.get(url)
2748
response.raise_for_status()
@@ -30,9 +51,13 @@ def pollevents(timestamp):
3051

3152
def main():
3253
global timestamp
54+
55+
parser = argparse.ArgumentParser(description="Listen to events in Maestro.")
56+
parser.add_argument("--kind", default="kbuild", help="The kind of events")
57+
args = parser.parse_args()
3358
while True:
3459
try:
35-
events = pollevents(timestamp)
60+
events = pollevents(timestamp, args.kind)
3661
if len(events) == 0:
3762
print("No new events, sleeping for 30 seconds")
3863
time.sleep(30)

0 commit comments

Comments
 (0)