This repository has been archived by the owner on Nov 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler.py
50 lines (40 loc) · 1.63 KB
/
scheduler.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
#!/usr/bin/env python3
import datetime
import os
import sched
import subprocess
import sys
import time
from os import path
REPOSITORY_DIR = path.dirname(path.abspath(__file__))
CHROME_DIR = path.abspath(path.join(REPOSITORY_DIR, '..', '..', 'project', 'chromium'))
AQUARIUM_DIR = path.abspath(path.join(REPOSITORY_DIR, '..', '..', 'project', 'aquarium'))
RUN_TRYJOB = path.join(REPOSITORY_DIR, 'bin', 'run_tryjob')
CHECK_TRYJOB = path.join(REPOSITORY_DIR, 'bin', 'check_tryjob')
def execute(command, dir=None):
subprocess.run(command, cwd=dir, shell=(sys.platform=='win32'))
def run_tryjob(job_type):
execute(['git', 'checkout', '.'], REPOSITORY_DIR)
execute(['git', 'fetch', 'origin'], REPOSITORY_DIR)
execute(['git', 'rebase', 'origin/master'], REPOSITORY_DIR)
cmd = [RUN_TRYJOB, '--update', '--email', '--chrome-dir', CHROME_DIR, '--job'] + job_type
cmd += ['--aquarium-dir', AQUARIUM_DIR] if 'aquarium' in job_type else []
execute(cmd)
if sys.platform == 'win32':
execute([CHECK_TRYJOB, '--dir', CHROME_DIR, '--email'])
def main():
scheduler = sched.scheduler(time.time, time.sleep)
test_time = None
while True:
today = datetime.date.today()
if not test_time or today > test_time.date():
test_date = today
else:
test_date = today + datetime.timedelta(days=1)
test_time = datetime.datetime(test_date.year, test_date.month, test_date.day, 20, 0)
print('\nTest time: ' + test_time.strftime('%Y/%m/%d %H:%M'))
job_type = ['chrome', 'aquarium']
scheduler.enterabs(time.mktime(test_time.timetuple()), 1, run_tryjob, (job_type,))
scheduler.run()
if __name__ == '__main__':
sys.exit(main())