-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 parent
6f8498a
commit 102ee68
Showing
3 changed files
with
109 additions
and
0 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,5 @@ | ||
FROM python:3.10.6 | ||
ADD check.py . | ||
ADD requirements.txt . | ||
RUN pip install -r requirements.txt --no-cache-dir && rm -f requirements.txt | ||
CMD python check.py |
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,50 @@ | ||
import json | ||
import os | ||
import asyncio | ||
from aiomcache import Client | ||
|
||
memcached_host = os.environ.get('MEMCACHED_HOST') or 'localhost' | ||
|
||
alert_loop_time = os.environ.get('ALERT_PERIOD') or 3 | ||
|
||
|
||
async def alarm_data(mc, alerts_cached_data): | ||
try: | ||
task1_result = await mc.get(b"alerts") | ||
print(f"task result") | ||
|
||
if task1_result: | ||
encoded_result = json.loads(task1_result.decode('utf-8')) | ||
|
||
await asyncio.sleep(alert_loop_time) | ||
|
||
except Exception as e: | ||
print(f"Error fetching data: {str(e)}") | ||
raise | ||
|
||
|
||
async def main(): | ||
mc = Client(memcached_host, 11211) # Connect to your Memcache server | ||
alerts_cached_data = {} | ||
while True: | ||
try: | ||
print(f"task start") | ||
await alarm_data(mc, alerts_cached_data) | ||
|
||
except asyncio.CancelledError: | ||
print("Task canceled. Shutting down...") | ||
await mc.close() | ||
break | ||
|
||
except Exception as e: | ||
print(f"Caught an exception: {e}") | ||
|
||
finally: | ||
asyncio.sleep(1) | ||
|
||
if __name__ == "__main__": | ||
try: | ||
print("Start") | ||
asyncio.run(main()) | ||
except KeyboardInterrupt: | ||
pass |
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,54 @@ | ||
#!/bin/bash | ||
|
||
# Default values | ||
ALERT_TOKEN="" | ||
MEMCACHED_HOST="" | ||
|
||
# Check for arguments | ||
while [[ $# -gt 0 ]]; do | ||
case "$1" in | ||
-a|--alert-token) | ||
ALERT_TOKEN="$2" | ||
shift 2 | ||
;; | ||
-m|--memcached-host) | ||
MEMCACHED_HOST="$2" | ||
shift 2 | ||
;; | ||
*) | ||
echo "Unknown argument: $1" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
echo "ALERTS" | ||
|
||
echo "ALERT_TOKEN: $ALERT_TOKEN" | ||
echo "MEMCACHED_HOST: $MEMCACHED_HOST" | ||
|
||
|
||
# Updating the Git repo | ||
echo "Updating Git repo..." | ||
#cd /path/to/your/git/repo | ||
git pull | ||
|
||
# Moving to the deployment directory | ||
echo "Moving to deployment directory..." | ||
#cd /deploy/tcp_server | ||
|
||
# Building Docker image | ||
echo "Building Docker image..." | ||
docker build -t check -f DockerfileCheck . | ||
|
||
# Stopping and removing the old container (if exists) | ||
echo "Stopping and removing old container..." | ||
docker stop check || true | ||
docker rm check || true | ||
|
||
# Deploying the new container | ||
echo "Deploying new container..." | ||
docker run --name check --restart unless-stopped -d --env MEMCACHED_HOST="$MEMCACHED_HOST" check | ||
|
||
echo "Container deployed successfully!" | ||
|