-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
232 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,48 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# @Author: José Sánchez-Gallego (gallegoj@uw.edu) | ||
# @Date: 2024-03-25 | ||
# @Filename: overwatcher.py | ||
# @License: BSD 3-clause (http://www.opensource.org/licenses/BSD-3-Clause) | ||
|
||
from __future__ import annotations | ||
|
||
from fastapi import APIRouter | ||
|
||
from lvmapi.tools import get_redis_connection | ||
|
||
|
||
router = APIRouter(prefix="/overwatcher", tags=["overwatcher"]) | ||
|
||
|
||
@router.get("/") | ||
async def get_overwatcher(): | ||
"""Not implemented.""" | ||
|
||
return {} | ||
|
||
|
||
@router.get("/enabled", description="Is the overwatcher enabled?") | ||
def get_overwatcher_enabled() -> bool: | ||
"""Returns whether the overwatcher is enabled.""" | ||
|
||
redis = get_redis_connection() | ||
|
||
enabled = redis.get("overwatcher:enabled") | ||
assert enabled is None or isinstance(enabled, str) | ||
|
||
if enabled is None: | ||
return False | ||
|
||
return bool(int(enabled)) | ||
|
||
|
||
@router.put("/enabled/{enabled}", description="Enable or disable the overwatcher") | ||
def put_overwatcher_enabled(enabled: bool) -> bool: | ||
"""Enables or disables the overwatcher.""" | ||
|
||
redis = get_redis_connection() | ||
redis.set("overwatcher:enabled", int(enabled)) | ||
|
||
return enabled |
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,20 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# @Author: José Sánchez-Gallego (gallegoj@uw.edu) | ||
# @Date: 2024-03-25 | ||
# @Filename: redis.py | ||
# @License: BSD 3-clause (http://www.opensource.org/licenses/BSD-3-Clause) | ||
|
||
from __future__ import annotations | ||
|
||
import redis | ||
|
||
|
||
__all__ = ["get_redis_connection"] | ||
|
||
|
||
def get_redis_connection() -> redis.Redis: | ||
"""Returns a connection to the Redis server.""" | ||
|
||
return redis.Redis(host="10.8.38.26", port=6379, db=0, decode_responses=True) |