Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

Commit c51c966

Browse files
authored
Merge pull request #95 from edx/yro/update_logging
Yro/update logging
2 parents 249d340 + bac906f commit c51c966

30 files changed

+449
-568
lines changed

VEDA/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
sys.path.append(os.path.abspath(__file__))
55
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'VEDA.settings.local')
66

7+
# pep8: disable=E402
78
from django.conf import settings
89
from rest_framework import routers
9-
# from rest_framework.routers import DefaultRouter
1010
from django.conf.urls import patterns, include, url
1111
from django.contrib import admin
1212

VEDA_OS01/fixtures/destinations.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@
5656
"fields": {
5757
"course_name": "Veda Sandbox Test Course",
5858
"course_hold": true,
59-
"institution": "XXX",
60-
"edx_classid": "XXXXX",
59+
"institution": "EDX",
60+
"edx_classid": "DEMOX",
6161
"semesterid": "2017",
6262
"yt_proc": false,
6363
"tp_proc": false,
6464
"c24_proc": false,
6565
"s3_proc": true,
6666
"local_storedir": "course-v1:VEDA+VEDA201+2015_T1",
67-
"studio_hex": "xxxx"
67+
"studio_hex": "shared_course_token"
6868
}
6969
}
7070
]

VEDA_OS01/fixtures/encodes.json

+13
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,18 @@
160160
"encode_resolution": "720",
161161
"product_spec": "desktop_webm"
162162
}
163+
},
164+
{
165+
"model": "VEDA_OS01.course",
166+
"pk": 1,
167+
"fields": {
168+
"course_name": "Demo Course",
169+
"institution": "EDX",
170+
"edx_classid": "DEMOX",
171+
"semesterid": 2018,
172+
"yt_proc": false,
173+
"local_storedir": "this/is/an/exemplar",
174+
"studio_hex": "shared_course_token"
175+
}
163176
}
164177
]

bin/deliver

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if project_path not in sys.path:
99
sys.path.append(project_path)
1010

1111

12-
class DeliverCli:
12+
class DeliverCli(object):
1313
"""
1414
Deliver
1515

bin/heal

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ Deliver
44
55
Command Line Interface
66
"""
7-
import os
8-
import sys
97
import argparse
108
import datetime
119
from datetime import timedelta
10+
import logging
11+
import os
12+
import sys
1213
import pytz
1314

1415
project_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -21,8 +22,12 @@ from VEDA_OS01.models import Course, Video
2122
from VEDA_OS01.transcripts import retrieve_three_play_translations
2223
from VEDA.utils import get_config
2324

25+
LOGGER = logging.getLogger(__name__)
26+
# TODO: Remove this temporary logging to stdout
27+
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
28+
2429

25-
class HealCli:
30+
class HealCli(object):
2631

2732
def __init__(self, **kwargs):
2833
self.logging = kwargs.get('logging', True)
@@ -93,8 +98,8 @@ def main():
9398
retrieve_three_play_translations()
9499
return
95100

96-
print '%s - %s: %s' % ('Healing', 'VEDA ID', veda_id)
97-
print '%s - %s: %s' % ('Healing', 'Course', course_id)
101+
LOGGER.info('%s - %s: %s' % ('Healing', 'VEDA ID', veda_id))
102+
LOGGER.info('%s - %s: %s' % ('Healing', 'Course', course_id))
98103

99104
if veda_id is None and course_id is None and schedule is False:
100105
VH = VedaHeal()

bin/ingest

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/usr/bin/env python
2+
"""
3+
Ingest
4+
5+
Command Line Interface
6+
"""
7+
28
import os
39
import sys
410
import argparse
@@ -9,13 +15,8 @@ if project_path not in sys.path:
915

1016
from control.veda_utils import EmailAlert
1117

12-
"""
13-
Ingest
14-
15-
Command Line Interface
16-
"""
1718

18-
class IngestCli():
19+
class IngestCli(object):
1920

2021
def __init__(self, **kwargs):
2122
self.args = None

bin/loop.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#!/usr/bin/env python
2+
"""
3+
This is a cheapo way to get a pager (using SES)
4+
5+
"""
26

37
import os
48
import sys
59
import argparse
10+
import logging
611
from django.db import reset_queries
712
import resource
813
import time
@@ -13,20 +18,19 @@
1318
if project_path not in sys.path:
1419
sys.path.append(project_path)
1520

16-
"""
17-
This is a cheapo way to get a pager (using SES)
18-
19-
"""
20-
2121
import django
2222
django.setup()
2323

2424
from control.veda_file_discovery import FileDiscovery
2525
from youtube_callback.daemon import generate_course_list
2626
from youtube_callback.sftp_id_retrieve import callfunction
2727

28+
LOGGER = logging.getLogger(__name__)
29+
# TODO: Remove this temporary logging to stdout
30+
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
31+
2832

29-
class DaemonCli:
33+
class DaemonCli(object):
3034

3135
def __init__(self):
3236
self.args = None
@@ -80,20 +84,20 @@ def ingest_daemon(self):
8084
reset_queries()
8185
x += 1
8286
if x >= 100:
83-
print 'Memory usage: %s (kb)' % resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
87+
LOGGER.info('Memory usage: %s (kb)' % resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
8488
x = 0
8589

8690
def youtube_daemon(self):
8791
x = 0
8892
while True:
8993
self.course_list = generate_course_list()
9094
for course in self.course_list:
91-
print "%s%s: Callback" % (course.institution, course.edx_classid)
95+
LOGGER.info('%s%s: Callback' % (course.institution, course.edx_classid))
9296
callfunction(course)
9397

9498
x += 1
9599
if x >= 100:
96-
print 'Memory usage: %s (kb)' % resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
100+
LOGGER.info('Memory usage: %s (kb)' % resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
97101
x = 0
98102

99103
reset_queries()

bin/youtubecallback

+2-16
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Command Line Interface
1818
"""
1919

2020

21-
class YoutubeCallbackCli():
21+
class YoutubeCallbackCli(object):
2222

2323
def __init__(self, **kwargs):
2424
self.args = None
@@ -54,14 +54,10 @@ class YoutubeCallbackCli():
5454

5555
def _parse_args(self):
5656
self.course_id = self.args.courseid
57-
self.list = self.args.list
5857

5958
def run(self):
6059

61-
if self.list is True:
62-
self.listcourses()
63-
else:
64-
self.loop()
60+
self.loop()
6561

6662
def loop(self):
6763
"""
@@ -82,16 +78,6 @@ class YoutubeCallbackCli():
8278
E1 = EmailAlert(message='Youtube Callback Daemon Crash', subject='Youtube Callback Daemon')
8379
E1.email()
8480

85-
def listcourses(self):
86-
"""
87-
list and exit
88-
:return:
89-
"""
90-
self.course_list = generate_course_list()
91-
for course in self.course_list:
92-
print course.institution
93-
print course.edx_classid
94-
9581

9682
def main():
9783
YTCC = YoutubeCallbackCli()

control/celeryapp.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@
44

55
from __future__ import absolute_import
66

7-
import os
87
from celery import Celery
9-
from VEDA.utils import get_config
8+
import logging
9+
import os
10+
import sys
1011

12+
from VEDA.utils import get_config
1113
try:
1214
from control.veda_deliver import VedaDelivery
1315
except ImportError:
1416
from veda_deliver import VedaDelivery
1517

18+
LOGGER = logging.getLogger(__name__)
19+
# TODO: Remove this temporary logging to stdout
20+
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
1621

1722
auth_dict = get_config()
1823

@@ -42,7 +47,7 @@
4247

4348
@app.task(name='worker_encode')
4449
def worker_task_fire(veda_id, encode_profile, jobid):
45-
print '[ENCODE] Misfire : {id} : {encode}'.format(id=veda_id, encode=encode_profile)
50+
LOGGER.info('[ENCODE] Misfire : {id} : {encode}'.format(id=veda_id, encode=encode_profile))
4651
return 1
4752

4853

control/old_veda_deliver_cielo.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import requests
2-
import ast
3-
import urllib
4-
51
"""
62
Cielo24 API Job Start and Download
73
Options (reflected in Course.models):
@@ -14,10 +10,17 @@
1410
priority (48h)
1511
turnaround_hours = number, overrides 'priority' call, will change a standard to a priority silently
1612
"""
13+
import logging
14+
import requests
15+
import ast
16+
import urllib
17+
1718
from control_env import *
18-
from veda_utils import ErrorObject
1919

2020
requests.packages.urllib3.disable_warnings()
21+
LOGGER = logging.getLogger(__name__)
22+
# TODO: Remove this temporary logging to stdout
23+
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
2124

2225

2326
class Cielo24TranscriptOld(object):
@@ -77,11 +80,9 @@ def retrieve_defaults(self):
7780
videoID=video_query,
7881
encode_url__icontains='_DTH.mp4',
7982
).latest()
80-
83+
8184
if video_query.inst_class.c24_username is None:
82-
ErrorObject.print_error(
83-
message='Cielo24 Record Incomplete',
84-
)
85+
LOGGER.error('[VIDEO_PIPELINE] {id} : Cielo API : Course record incomplete'.format(id=self.veda_id))
8586
return None
8687

8788
c24_defaults = {
@@ -102,10 +103,8 @@ def tokengenerator(self):
102103
# Generate Token
103104
r1 = requests.get(token_url)
104105
if r1.status_code > 299:
105-
ErrorObject.print_error(
106-
message='Cielo24 API Access Error',
107-
)
108-
return None
106+
LOGGER.error('[VIDEO_PIPELINE] {id} : Cielo API access'.format(id=self.veda_id))
107+
return
109108
api_token = ast.literal_eval(r1.text)["ApiToken"]
110109
return api_token
111110

@@ -161,7 +160,6 @@ def embed_url(self, api_token, job_id):
161160
urllib.quote_plus(self.c24_defaults['url'])
162161
))
163162
)
164-
print str(r4.status_code) + ' : Cielo24 Status Code'
165163
return ast.literal_eval(r4.text)['TaskId']
166164

167165

control/tests/test_encode.py

-27
Original file line numberDiff line numberDiff line change
@@ -81,30 +81,3 @@ def test_encode_url(self):
8181
).delete()
8282
encode_list = self.E.determine_encodes()
8383
self.assertTrue(len(encode_list) == baseline)
84-
85-
86-
def main():
87-
unittest.main()
88-
89-
90-
if __name__ == '__main__':
91-
sys.exit(main())
92-
93-
'''
94-
Save for poss future test
95-
96-
# import celeryapp
97-
98-
# co = Course.objects.get(institution='XXX', edx_classid='C93BC')
99-
# vid = 'XXXC93BC2016-V003500'
100-
# v = VedaEncode(course_object=co, veda_id=vid)
101-
# encode_list = v.determine_encodes()
102-
# for e in encode_list:
103-
# veda_id = vid
104-
# encode_profile = e
105-
# jobid = uuid.uuid1().hex[0:10]
106-
# # celeryapp.worker_task_fire.apply_async(
107-
# # (veda_id, encode_profile, jobid),
108-
# # queue='encode_worker'
109-
# # )
110-
'''

control/tests/test_file_discovery.py

-16
Original file line numberDiff line numberDiff line change
@@ -169,22 +169,6 @@ def test_discover_studio_ingested_videos(self, mock_validate_and_feed_to_ingest)
169169
file_discovery_instance.discover_studio_ingested_videos()
170170
self.assertTrue(mock_validate_and_feed_to_ingest.called)
171171

172-
@ddt.data(
173-
('veda/working', '[File Ingest] S3 Ingest Connection Failure'),
174-
(None, '[File Ingest] No Working Node directory')
175-
)
176-
@ddt.unpack
177-
@patch('control.veda_file_discovery.ErrorObject.print_error')
178-
@patch('boto.s3.connection.S3Connection')
179-
def test_discover_studio_ingested_video_exceptions(self, work_dir, error_message, mocked_s3_conn, mock_error):
180-
"""
181-
Tests 'FileDiscovery.discover_studio_ingested_videos' exception cases.
182-
"""
183-
mocked_s3_conn.side_effect = S3ResponseError('Error', 'Timeout')
184-
file_discovery_instance = FileDiscovery(node_work_directory=work_dir)
185-
file_discovery_instance.discover_studio_ingested_videos()
186-
mock_error.assert_called_with(message=error_message)
187-
188172
@ddt.data(
189173
(None, 'invalid_course_key'),
190174
('non-existent-hex', None)

0 commit comments

Comments
 (0)