Automatizado
This commit is contained in:
1
automation/crontab
Normal file
1
automation/crontab
Normal file
@ -0,0 +1 @@
|
|||||||
|
0 2 * * */1 curl http://app-server/update
|
70
automation/src/money/main.py
Normal file
70
automation/src/money/main.py
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
import argparse
|
||||||
|
import keyboard
|
||||||
|
import datetime
|
||||||
|
import time
|
||||||
|
import httpx
|
||||||
|
|
||||||
|
from threading import Event, Thread
|
||||||
|
|
||||||
|
|
||||||
|
def update(url: str):
|
||||||
|
r = httpx.get(url)
|
||||||
|
|
||||||
|
|
||||||
|
def update_thread(stop: Event, url: str):
|
||||||
|
t = datetime.time(hour=2)
|
||||||
|
print('Starting update thread.')
|
||||||
|
while True:
|
||||||
|
if stop.isSet():
|
||||||
|
break
|
||||||
|
|
||||||
|
if datetime.time() == t:
|
||||||
|
print('Updating.')
|
||||||
|
update(url)
|
||||||
|
|
||||||
|
print('Sleep')
|
||||||
|
time.sleep(60 * 60 * 5)
|
||||||
|
print('Stop update thread.')
|
||||||
|
|
||||||
|
|
||||||
|
def main_thread(stop: Event):
|
||||||
|
print('Starting main thread.')
|
||||||
|
while True:
|
||||||
|
if stop.isSet():
|
||||||
|
break
|
||||||
|
try:
|
||||||
|
if keyboard.is_pressed('q'):
|
||||||
|
print('Stop')
|
||||||
|
stop.set()
|
||||||
|
break
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print('Stop2')
|
||||||
|
stop.set()
|
||||||
|
break
|
||||||
|
print('Stop main thread.')
|
||||||
|
|
||||||
|
|
||||||
|
def main(args):
|
||||||
|
print('Main')
|
||||||
|
stop_signal = Event()
|
||||||
|
threads = [
|
||||||
|
Thread(target=update_thread, args=(stop_signal, args.url, )),
|
||||||
|
Thread(target=main_thread, args=(stop_signal,))
|
||||||
|
]
|
||||||
|
[t.start() for t in threads]
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
if True not in [t.is_alive() for t in threads]:
|
||||||
|
break
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print('Stop Main')
|
||||||
|
stop_signal.set()
|
||||||
|
break
|
||||||
|
[t.join() for t in threads]
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('-u', '--url', help='API Url', default='http://localhost:8081/update')
|
||||||
|
_args = parser.parse_args()
|
||||||
|
main(_args)
|
@ -11,7 +11,6 @@ services:
|
|||||||
- ./app/docker/nginx.conf:/etc/nginx/conf.d/default.conf
|
- ./app/docker/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||||
depends_on:
|
depends_on:
|
||||||
- app-php
|
- app-php
|
||||||
|
|
||||||
app-php:
|
app-php:
|
||||||
container_name: money_app_php
|
container_name: money_app_php
|
||||||
build:
|
build:
|
||||||
@ -21,6 +20,11 @@ services:
|
|||||||
- .:/code
|
- .:/code
|
||||||
ports:
|
ports:
|
||||||
- 9123:9000
|
- 9123:9000
|
||||||
|
app-cron:
|
||||||
|
image: sleeck/crond
|
||||||
|
volumes:
|
||||||
|
- ./automation/crontab:/etc/cron.d/auto-crontab
|
||||||
|
- ./automation/logs:/var/log/cron
|
||||||
|
|
||||||
ui-server:
|
ui-server:
|
||||||
container_name: money_ui
|
container_name: money_ui
|
||||||
@ -32,7 +36,6 @@ services:
|
|||||||
- ./ui/docker/nginx.conf:/etc/nginx/conf.d/default.conf
|
- ./ui/docker/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||||
depends_on:
|
depends_on:
|
||||||
- ui-php
|
- ui-php
|
||||||
|
|
||||||
ui-php:
|
ui-php:
|
||||||
container_name: money_ui_php
|
container_name: money_ui_php
|
||||||
build:
|
build:
|
||||||
@ -53,7 +56,6 @@ services:
|
|||||||
- ./ws/docker/nginx.conf:/etc/nginx/conf.d/default.conf
|
- ./ws/docker/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||||
depends_on:
|
depends_on:
|
||||||
- ws-php
|
- ws-php
|
||||||
|
|
||||||
ws-php:
|
ws-php:
|
||||||
container_name: money_ws_php
|
container_name: money_ws_php
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@ -63,7 +65,6 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- .:/code
|
- .:/code
|
||||||
|
|
||||||
|
|
||||||
db:
|
db:
|
||||||
container_name: money_db
|
container_name: money_db
|
||||||
image: mariadb:latest
|
image: mariadb:latest
|
||||||
@ -77,7 +78,6 @@ services:
|
|||||||
MYSQL_PASSWORD: 'money_pass'
|
MYSQL_PASSWORD: 'money_pass'
|
||||||
volumes:
|
volumes:
|
||||||
- dbdata:/var/lib/mysql
|
- dbdata:/var/lib/mysql
|
||||||
|
|
||||||
adminer:
|
adminer:
|
||||||
container_name: money_adminer
|
container_name: money_adminer
|
||||||
image: adminer:latest
|
image: adminer:latest
|
||||||
|
Reference in New Issue
Block a user