-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #263 from canonical/agent_status_endpoint
Add job status endpoint to server
- Loading branch information
Showing
18 changed files
with
552 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright (C) 2024 Canonical | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/> | ||
|
||
|
||
from datetime import timezone, datetime | ||
|
||
from testflinger_agent.client import TestflingerClient | ||
from testflinger_common.enums import TestEvent | ||
|
||
|
||
class EventEmitter: | ||
def __init__( | ||
self, | ||
job_queue: str, | ||
webhook: str, | ||
client: TestflingerClient, | ||
job_id: str, | ||
): | ||
""" | ||
:param job_queue: | ||
String representing job_queue the running job belongs to | ||
:param webhook: | ||
String url to send status updates to | ||
:param client: | ||
TestflingerClient used to post status updates to the server | ||
:param job_id: | ||
id for the job on which we want to post updates | ||
""" | ||
self.job_queue = job_queue | ||
self.webhook = webhook | ||
self.events = [] | ||
self.client = client | ||
self.job_id = job_id | ||
|
||
def emit_event(self, test_event: TestEvent, detail: str = ""): | ||
if test_event is not None: | ||
new_event_json = { | ||
"event_name": test_event, | ||
"timestamp": datetime.now(timezone.utc).isoformat(), | ||
"detail": detail, | ||
} | ||
self.events.append(new_event_json) | ||
self.client.post_status_update( | ||
self.job_queue, self.webhook, self.events, self.job_id | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.