-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
52 lines (36 loc) · 1.12 KB
/
app.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
#! /usr/bin/python
import gevent
from apscheduler.schedulers.gevent import GeventScheduler
from services.bulkSMSService import BulkSMSService
import logging
import redis
import datetime
import settings
r = redis.StrictRedis(host='localhost', port=6379, db=0)
import newrelic.agent
application = newrelic.agent.application()
class App:
@newrelic.agent.background_task(application)
def run(self):
date = r.get('CrunchDate')
date_1 = datetime.datetime.strptime(date, "%Y-%m-%d")
next_date = str((date_1 + datetime.timedelta(days = 1))).split(' ')[0]
r.set('CrunchDate', next_date)
service = BulkSMSService()
# services = [services]
# map(s.fetch, services)
# x foreach - x.fetch
service.fetchStats(
username = None,
date = date
)
if __name__ == '__main__':
logging.basicConfig()
app = App()
scheduler = GeventScheduler()
scheduler.add_job(app.run, 'interval', minutes=3, id='stats')
g = scheduler.start()
try:
g.join()
except (KeyboardInterrupt, SystemExit):
pass