-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update/cleanup; added Queue class in server for better "instancing"; …
…restructured files for Dockerfile
- Loading branch information
Showing
3 changed files
with
135 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import requests | ||
from rich import print | ||
|
||
|
||
class RestQueue: | ||
def __init__(self, host: str, port: int, queue_name: str): | ||
self._host = host | ||
self._port = port | ||
self._queue_name = queue_name | ||
self._queue_url = f"http://{host}:{port}/queues/{queue_name}" | ||
self._session = requests.Session() | ||
|
||
def create(self): | ||
response = self._session.post(self._queue_url) | ||
return response.status_code, response.json() | ||
|
||
def push(self, value): | ||
if value is None: | ||
print(f"pushed value cannot be None") | ||
return | ||
|
||
url = f"{self._queue_url}/push" | ||
response = self._session.post(url, params={"value": value}) | ||
if response.status_code == 404: | ||
print(f"no such queue {self._queue_name!r}") | ||
|
||
return response.json() | ||
|
||
def pop(self): | ||
url = f"{self._queue_url}/pop" | ||
response = self._session.post(url) | ||
if response.status_code == 404: | ||
print(f"no such queue {self._queue_name!r}") | ||
return | ||
|
||
return response.json() | ||
|
||
def list(self): | ||
url = self._queue_url | ||
response = self._session.get(url) | ||
if response.status_code == 404: | ||
print(f"no such queue {self._queue_name!r}") | ||
return | ||
|
||
return response.json() | ||
|
||
|
||
if __name__ == '__main__': | ||
qname = "test" | ||
rq = RestQueue("localhost", 8000, qname) | ||
print(rq.create()) | ||
|
||
print(rq.push(100)) | ||
print(rq.push("secret message")) | ||
print(rq.push(3.14159)) | ||
print(rq.push(True)) | ||
|
||
print(rq.list()) | ||
|
||
print(rq.pop()) |
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