forked from swar/Swar-Chia-Plot-Manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stateless-manager.py
69 lines (57 loc) · 2.69 KB
/
stateless-manager.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import logging
import time
from datetime import datetime, timedelta
from plotmanager.library.parse.configuration import get_config_info
from plotmanager.library.utilities.jobs import has_active_jobs_and_work, load_jobs, monitor_jobs_to_start
from plotmanager.library.utilities.log import check_log_progress
from plotmanager.library.utilities.processes import get_running_plots
chia_location, log_directory, config_jobs, manager_check_interval, max_concurrent, progress_settings, \
notification_settings, debug_level, view_settings = get_config_info()
logging.basicConfig(format='%(asctime)s [%(levelname)s]: %(message)s', datefmt='%Y-%m-%d %H:%M:%S', level=debug_level)
logging.info(f'Debug Level: {debug_level}')
logging.info(f'Chia Location: {chia_location}')
logging.info(f'Log Directory: {log_directory}')
logging.info(f'Jobs: {config_jobs}')
logging.info(f'Manager Check Interval: {manager_check_interval}')
logging.info(f'Max Concurrent: {max_concurrent}')
logging.info(f'Progress Settings: {progress_settings}')
logging.info(f'Notification Settings: {notification_settings}')
logging.info(f'View Settings: {view_settings}')
logging.info(f'Loading jobs into objects.')
jobs = load_jobs(config_jobs)
next_log_check = datetime.now()
next_job_work = {}
running_work = {}
logging.info(f'Grabbing running plots.')
jobs, running_work = get_running_plots(jobs, running_work)
for job in jobs:
max_date = None
for pid in job.running_work:
work = running_work[pid]
start = work.datetime_start
if not max_date or start > max_date:
max_date = start
if not max_date:
continue
next_job_work[job.name] = max_date + timedelta(minutes=job.stagger_minutes)
logging.info(f'{job.name} Found. Setting next stagger date to {next_job_work[job.name]}')
logging.info(f'Starting loop.')
while has_active_jobs_and_work(jobs):
# CHECK LOGS FOR DELETED WORK
logging.info(f'Checking log progress..')
check_log_progress(jobs=jobs, running_work=running_work, progress_settings=progress_settings,
notification_settings=notification_settings, view_settings=view_settings)
next_log_check = datetime.now() + timedelta(seconds=manager_check_interval)
# DETERMINE IF JOB NEEDS TO START
logging.info(f'Monitoring jobs to start.')
jobs, running_work, next_job_work, next_log_check = monitor_jobs_to_start(
jobs=jobs,
running_work=running_work,
max_concurrent=max_concurrent,
next_job_work=next_job_work,
chia_location=chia_location,
log_directory=log_directory,
next_log_check=next_log_check,
)
logging.info(f'Sleeping for {manager_check_interval} seconds.')
time.sleep(manager_check_interval)