forked from JunyuanChen/SonnyBot-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.py
More file actions
38 lines (30 loc) · 791 Bytes
/
Copy pathtimer.py
File metadata and controls
38 lines (30 loc) · 791 Bytes
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
# coding: utf-8
import time
import threading
import functools
import logger
import storage
def periodic(interval):
def decorator(func):
@functools.wraps(func)
def loop(*args, **kwargs):
while True:
time.sleep(interval)
func(*args, **kwargs)
@functools.wraps(func)
def decorated(*args, **kwargs):
thread = threading.Thread(
target=loop,
args=args,
kwargs=kwargs,
daemon=True
)
thread.start()
return thread
return decorated
return decorator
@periodic(20 * 60)
def sync_to_remote():
with storage.LOCK:
logger.info("[TIMER] Periodic sync started")
storage.sync()