-
Notifications
You must be signed in to change notification settings - Fork 2
/
Clock.py
64 lines (49 loc) · 1.88 KB
/
Clock.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
"""
This is used to start the automation process when the web app is deployed on heroku
if you running it in development stage it is not going to be in use
"""
from apscheduler.schedulers.blocking import BlockingScheduler
import requests
from app import MongoOperations as mo, CaidaMeasure as cm, IpFetcher as ipf, SpeedcheckerMeasure as sc, \
RipeMeasure as rm
ip_Africa_address = []
trace_done = False # for the first initial start of trace
sched = BlockingScheduler()
@sched.scheduled_job('interval', minutes=180) # 180
def timed_job_3hours():
if len(ip_Africa_address) > 0:
global trace_done
trace_done = True
sc.post_trace_all_ip_test(ip_Africa_address)
rm.post_trace_all_ip_test(ip_Africa_address)
cm.post_trace_all_ip_test(ip_Africa_address)
@sched.scheduled_job('interval', minutes=220) # 220
def timed_job_3hours40():
if trace_done:
sc.get_trace_all_result()
rm.get_trace_all_result()
cm.get_trace_all_result()
mo.delete_empty_traces("SpeedChecker")
mo.delete_empty_traces("CAIDA")
mo.delete_empty_traces("RIPE")
mo.get_linked_asn("SpeedChecker")
mo.get_linked_asn("CAIDA")
mo.get_linked_asn("RIPE")
mo.get_asn_location("SpeedChecker")
mo.get_asn_location("CAIDA")
mo.get_asn_location("RIPE")
@sched.scheduled_job('interval', minutes=1440) # 1440
def timed_job_24hours():
global ip_Africa_address
ipf.scrape_africa_asn()
ip_Africa_address = ipf.get_random_africa_ip()
# print(len(ip_Africa_address))
"""
Making a get request every 25 minutes to keep the app alive and
not to go on sleep mode since we are using the free version of heroku
"""
@sched.scheduled_job('interval', minutes=25)
def timed_job_3hours():
response = requests.get('https://africa-s-internet-topology.herokuapp.com/')
print(response.url)
sched.start()