This repository has been archived by the owner on Oct 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
heal
executable file
·172 lines (139 loc) · 4.51 KB
/
heal
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env python
"""
Deliver
Command Line Interface
"""
import argparse
import datetime
from datetime import timedelta
import logging
import os
import sys
import pytz
project_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if project_path not in sys.path:
sys.path.append(project_path)
from control.celeryapp import maintainer_healer
from control.veda_heal import VedaHeal
from VEDA_OS01.models import Course, Video
from VEDA_OS01.transcripts import retrieve_three_play_translations
from VEDA.utils import get_config
LOGGER = logging.getLogger(__name__)
# TODO: Remove this temporary logging to stdout
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
class HealCli(object):
def __init__(self, **kwargs):
self.logging = kwargs.get('logging', True)
self.binscript = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'heal')
def schedule(self):
"""
Reschedule Heal process via Celery ETA
"""
auth_dict = get_config()
go_time = datetime.datetime.now(pytz.timezone("America/New_York")) \
.replace(hour=0, minute=0, second=0, microsecond=0) \
.astimezone(pytz.utc) + timedelta(days=1)
maintainer_healer.apply_async((self.binscript,), queue=auth_dict['celery_heal_queue'], eta=go_time)
def main():
"""
Maintenance Daemon + ETA dialer for healing
"""
parser = argparse.ArgumentParser()
parser.usage = '''
{cmd} -i veda_id
{cmd} -c course_id
{cmd} -s schedule
{cmd} -t veda_institution_id
{cmd} --process-translations
{cmd} --no_audio
[-i -c -s -t --process-translations --no_audio]
Use --help to see all options.
'''.format(cmd=sys.argv[0])
parser.add_argument(
'-i', '--veda_id',
default=None,
help='VEDA ID'
)
parser.add_argument(
'-c', '--course_id',
help='Course ID',
)
parser.add_argument(
'-s', '--schedule',
help='Trigger Scheduler',
action='store_true'
)
parser.add_argument(
'-t', '--veda_institution_id',
help='Veda institution ID used with course heal',
default=None
)
parser.add_argument(
'--process-translations',
dest='process_translations',
help='Retrieves completed 3PlayMedia translations for the videos.',
action='store_true'
)
parser.add_argument(
'--no_audio',
help='Removes audio_mp3 from encode list.',
action='store_true'
)
args = parser.parse_args()
veda_id = args.veda_id
course_id = args.course_id
schedule = args.schedule
veda_institution_id = args.veda_institution_id
process_translations = args.process_translations
if process_translations:
# Only kick off a round of retrieving successful
# translations from 3Play Media
os.environ['DJANGO_SETTINGS_MODULE'] = 'VEDA.settings.production'
retrieve_three_play_translations()
return
LOGGER.info('%s - %s: %s' % ('Healing', 'VEDA ID', veda_id))
LOGGER.info('%s - %s: %s' % ('Healing', 'Course', course_id))
if veda_id is None and course_id is None and schedule is False:
VH = VedaHeal()
VH.discovery()
VH.purge()
# Kicks off a round of retrieving successful
# translations from 3Play Media
retrieve_three_play_translations()
HC = HealCli()
HC.schedule()
return
if veda_id is not None:
VH = VedaHeal(
video_query=Video.objects.filter(
edx_id=veda_id.strip()
),
no_audio=args.no_audio
)
VH.send_encodes()
return
if course_id is not None:
veda_institution=course_id[0:3]
veda_classid=course_id[3:8]
if veda_institution_id:
veda_institution = veda_institution_id
veda_classid = course_id.replace(veda_institution_id, '')
VH = VedaHeal(
video_query=Video.objects.filter(
inst_class=Course.objects.filter(
institution=veda_institution,
edx_classid=veda_classid
)
),
no_audio=args.no_audio
)
VH.send_encodes()
return
# TODO: Data backup
# TODO: API key purge
if schedule is True:
HC = HealCli()
HC.schedule()
return None
if __name__ == '__main__':
sys.exit(main())