Automatizado

This commit is contained in:
2021-04-12 00:43:39 -04:00
parent 35bcbd1979
commit 5129cca099
3 changed files with 76 additions and 5 deletions

1
automation/crontab Normal file
View File

@ -0,0 +1 @@
0 2 * * */1 curl http://app-server/update

View 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)

View File

@ -11,7 +11,6 @@ services:
- ./app/docker/nginx.conf:/etc/nginx/conf.d/default.conf
depends_on:
- app-php
app-php:
container_name: money_app_php
build:
@ -21,6 +20,11 @@ services:
- .:/code
ports:
- 9123:9000
app-cron:
image: sleeck/crond
volumes:
- ./automation/crontab:/etc/cron.d/auto-crontab
- ./automation/logs:/var/log/cron
ui-server:
container_name: money_ui
@ -32,7 +36,6 @@ services:
- ./ui/docker/nginx.conf:/etc/nginx/conf.d/default.conf
depends_on:
- ui-php
ui-php:
container_name: money_ui_php
build:
@ -53,7 +56,6 @@ services:
- ./ws/docker/nginx.conf:/etc/nginx/conf.d/default.conf
depends_on:
- ws-php
ws-php:
container_name: money_ws_php
restart: unless-stopped
@ -63,7 +65,6 @@ services:
volumes:
- .:/code
db:
container_name: money_db
image: mariadb:latest
@ -77,7 +78,6 @@ services:
MYSQL_PASSWORD: 'money_pass'
volumes:
- dbdata:/var/lib/mysql
adminer:
container_name: money_adminer
image: adminer:latest