-
Notifications
You must be signed in to change notification settings - Fork 5
/
runDownloadsNow.py
59 lines (51 loc) · 1.6 KB
/
runDownloadsNow.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
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File : runDownloads.py
@Time : 2023/10/24
@Author : Jacob Roy
@Version : 1.0
@Contact : [email protected]
@Desc :
'''
import multiprocessing
import time
import functools
from time import gmtime, strftime
from tidalrr.workers import tidalrrStart
from tidalrr.workers.downloadQueuedOthers import downloadQueuedCovers
from tidalrr.workers.downloadQueuedTracks import scanQueuedTracks
# This decorator can be applied to any job function to log the elapsed time of each job
def print_elapsed_time(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
start_timestamp = time.time()
print('LOG: Running job "%s"' % func.__name__)
result = func(*args, **kwargs)
print('LOG: Job "%s" completed in %d seconds' % (func.__name__, time.time() - start_timestamp))
return result
return wrapper
@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()
p.join()
# 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()
if __name__ == '__main__':
#startDownloads()
#main()
#mainSchedule()
forkDownloads()