-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaintenance.py
53 lines (43 loc) · 1.63 KB
/
maintenance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
from argparse import ArgumentParser
import setup_logging
from src.scheduler import UpdateScheduler, DbUtil
setup_logging.setup('debug')
logger = setup_logging.setup('maintenance')
parser = ArgumentParser()
parser.add_argument('--manga', '-m', type=int, required=True)
parser.add_argument('--update-interval', '-ui', action='store_true')
parser.add_argument('--update-estimate', '-ue', action='store_true')
parser.add_argument('--production', '-p', action='store_true')
args = parser.parse_args()
if args.production:
logger.warning('using production environment. Type yes to continue')
resp = input()
if resp.lower().strip() != 'yes':
logger.info('Cancelling')
exit()
os.environ['DB_HOST'] = os.environ['DB_HOST_PROD']
os.environ['DB_PASSWORD'] = os.environ['DB_PASSWORD_PROD']
scheduler = UpdateScheduler()
with scheduler.conn() as conn:
dbutil = DbUtil(conn, None)
try:
with conn.cursor() as cur:
if args.update_interval:
logger.info(f'Updating interval for {args.manga}')
dbutil.update_chapter_interval(args.manga, cur=cur)
if args.update_estimate:
logger.info(f'Updating estimate for {args.manga}')
dbutil.update_estimated_release(args.manga, cur=cur)
except Exception:
logger.exception('Failed to execute commands. Rolling back')
conn.rollback()
raise
print('Commit changes? (y/n)')
resp = input().strip().lower()
if resp in ('y', 'yes'):
print('Committing changes')
conn.commit()
else:
print('Rolling back changes')
conn.rollback()