forked from sisirkoppaka/articur8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
125 lines (106 loc) · 3.55 KB
/
fabfile.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from fabric.api import *
from fabric.colors import green, red
import psutil
import re
import redis
from articurate.fd.fd import startFD
from articurate.utils.config import *
#Start Motherlode
def start_motherlode(debug='False'):
if debug=='False':
local("cd ./articurate/motherlode && node app.js > /dev/null 2>&1 &")
print green("start_motherlode: Started Motherlode with Debug mode set to "+debug, bold=True)
else:
local("cd ./articurate/motherlode && node app.js > ../../motherlode.log 2>&1 &")
print green("start_motherlode: Started Motherlode with Debug mode set to "+debug, bold=True)
#Stop Motherlode
def stop_motherlode():
found = 'False';
for proc in psutil.process_iter():
try:
match = re.match(r'.*node.*',proc.name)
if match:
print green("stop_motherlode: Found process, stopping "+match.group()+".", bold=True)
proc.kill()
found = 'True'
except:
continue
#The below seems to not work, fix me.
if not found:
print green("stop_motherlode: Could not find process for Motherlode", bold=True)
#Restart Motherlode
def restart_motherlode(debug='False'):
stop_motherlode()
start_motherlode(debug)
print green("restart_motherlode: Finished restarting Motherlode ", bold=True)
#Setup Motherlode
def setup_motherlode():
local("cd ./articurate/motherlode && npm install")
print green("setup_motherlode: Finished satisfying prerequisites for Motherlode ", bold=True)
#Start Celery Worker
def start_celery_worker(debug='False'):
if debug=='False':
local('celery worker --app=articurate.celery -l info > /dev/null 2>&1 &')
print green("start_celery_worker: Started Celery Worker with Debug mode set to "+debug, bold=True)
else:
local("celery worker --app=articurate.celery -l info > ./celery.log 2>&1 &")
print green("start_motherlode: Started Motherlode with Debug mode set to "+debug, bold=True)
#Stop Celery Worker - REVISE later, works now
def stop_celery_worker():
found = 'False';
#for proc in psutil.process_iter():
#try:
#match = re.match(r'.*celery.*',proc.name)
# match = re.search(r'.*celery.*',proc.name)
# if match:
# print green("stop_celery_worker: Found process, stopping "+match.groups()+".", bold=True)
# proc.kill()
# found = 'True'
#except:
# pass
#The below seems to not work, fix me.
#if not found:
# print green("stop_celery_worker: Could not find process for Celery Worker", bold=True)
try:
local("ps auxww | grep celery | awk '{print $2}' | xargs kill -9")
print green("stop_celery_worker: Killed", bold=True)
except:
pass
#print green("stop_celery_worker: Killed", bold=True)
def flush_celery_redis():
try:
r = redis.StrictRedis(host='localhost',port=6379, db=1)
r.flushdb()
except:
pass
#Restart Motherlode
def restart_celery_worker(debug='False'):
stop_celery_worker()
flush_celery_redis()
start_celery_worker(debug)
print green("restart_celery_worker: Finished restarting Celery Worker ", bold=True)
#Kickstart everything
def kickstart(debug='False'):
setup_motherlode()
start_motherlode(debug)
start_celery_worker(debug)
print green("kickstart: Done!", bold=True)
#Kickstop everything
def kickstop():
stop_motherlode()
stop_celery_worker()
flush_celery_redis()
print green("kickstop: Done!", bold=True)
#Kickrestart everything
def kickrestart(debug='False'):
kickstop()
kickstart(debug)
print green("kickrestart: Done!", bold=True)
# collect articles on a cold start
def runFD_coldStart():
interval = config['fd.coldStartWindowSize']
startFD(interval)
# regular article collection (delta updates)
def runFD():
interval = config['fd.windowSize']
startFD(interval)