-
Notifications
You must be signed in to change notification settings - Fork 5
/
runSchedule.py
106 lines (95 loc) · 3.07 KB
/
runSchedule.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File : runScans.py
@Time : 2023/10/24
@Author : Jacob Roy
@Version : 1.0
@Contact : [email protected]
@Desc :
'''
import multiprocessing
import schedule
import time
from time import gmtime, strftime
from tidalrr.workers import print_elapsed_time, tidalrrStart
from tidalrr.workers.scanQueuedArtists import scanQueuedArtists
from tidalrr.workers.scanQueuedAlbums import scanQueuedAlbums
from tidalrr.workers.scanQueuedPlaylists import scanQueuedPlaylists
from tidalrr.workers.scanUserPlaylists import scanUserPlaylists
from tidalrr.database import getSettings
from tidalrr.workers.downloadQueuedOthers import downloadQueuedCovers
from tidalrr.workers.downloadQueuedTracks import scanQueuedTracks
@print_elapsed_time
def startScans():
settings = getSettings()
print(strftime("%Y-%m-%d %H:%M:%S", gmtime())+" startScans")
tidalrrStart()
print('tidalrrStart')
scanQueuedArtists()
print('Done scanning artists')
scanQueuedAlbums()
print('Done scanning albums')
#scanQueuedTracks()
#print('scanQueuedTracks')
if settings.scanUserPlaylists:
scanUserPlaylists()
print('scanUserPlaylist')
scanQueuedPlaylists()
print('scanQueuedPlaylists')
def forkScans():
# Start foo as a process
print(strftime("%Y-%m-%d %H:%M:%S", gmtime())+" Starting scans")
p = multiprocessing.Process(target=startScans)
p.start()
# Wait a maximum of 10 seconds for foo
# Usage: join([timeout in seconds])
settings = getSettings()
hours = int(settings.scansDuration)
seconds = hours * 60 * 60
p.join(seconds)
# If thread is active
if p.is_alive():
print(strftime("%Y-%m-%d %H:%M:%S", gmtime())+" Scans are running... let's kill it...")
# Terminate foo
p.terminate()
# Cleanup
p.join()
@print_elapsed_time
def startDownloads():
print(strftime("%Y-%m-%d %H:%M:%S", gmtime())+" startDownloads")
tidalrrStart()
downloadQueuedCovers()
scanQueuedTracks()
def forkDownloads():
# Start foo as a process
print(strftime("%Y-%m-%d %H:%M:%S", gmtime())+" Starting downloads")
p = multiprocessing.Process(target=startDownloads)
p.start()
# Wait a maximum of 10 seconds for foo
# Usage: join([timeout in seconds])
settings = getSettings()
hours = int(settings.downloadsDuration)
seconds = hours * 60 * 60
p.join(seconds)
# If thread is active
if p.is_alive():
print(strftime("%Y-%m-%d %H:%M:%S", gmtime())+" Downloads are running... let's kill it...")
# Terminate foo
p.terminate()
# Cleanup
p.join()
def mainSchedule():
settings = getSettings()
if settings.scansDuration != 0:
print('Scans are scheduled')
schedule.every().day.at(str(settings.scansStartHour).zfill(2)+":00").do(forkScans)
if settings.downloadsDuration != 0:
print('Downloads are scheduled')
while True:
schedule.run_pending()
time.sleep(1)
if __name__ == '__main__':
#startScans()
#main()
mainSchedule()