r80986 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80985‎ | r80986 | r80987 >
Date:20:20, 25 January 2011
Author:diederik
Status:deferred
Tags:
Comment:
Added support for chart type jobs.
Modified paths:
  • /trunk/tools/editor_trends/cronjobs.py (modified) (history)

Diff [purge]

Index: trunk/tools/editor_trends/cronjobs.py
@@ -19,14 +19,16 @@
2020
2121 from multiprocessing import Process
2222
 23+import manage as manager
2324
2425 from database import db
2526 from classes import wikiprojects
26 -import manage as manager
 27+from analyses import analyzer
2728
 29+
2830 def launch_editor_trends_toolkit(task):
2931 '''
30 - This function should only be called as a cronjob.
 32+ This function should only be called as a cronjob and not directly.
3133 '''
3234 parser, settings, wiki = manager.init_args_parser()
3335 args = parser.parse_args(['django'])
@@ -34,37 +36,77 @@
3537 args.project = task['project']
3638 print args
3739 wiki = wikiprojects.Wiki(settings, args)
38 - manager.all_launcher(wiki, settings, None)
39 - #wiki.update_language(language)
40 - #wiki.update_project(project)
 40+ res = manager.all_launcher(wiki, settings, None)
 41+ return res
4142
42 - #p = Process(target=manager.all_launcher, args=(wiki, settings, None))
43 - #p.start()
4443
45 -def launch_chart(project, language):
46 - pass
 44+def launch_chart(task):
 45+ '''
 46+ This function should only be called as a cronjob and not directly.
 47+ '''
 48+ res = True
 49+ try:
 50+ project = task['project']
 51+ language_code = task['language_code']
 52+ func = task['jobtype']
4753
 54+ collection = 'editors_dataset' #FIXME hardcoded string
 55+ time_unit = 'month' #FIXME hardcoded string
 56+ cutoff = 1 #FIXME hardcoded string
 57+ cum_cutoff = 50 #FIXME hardcoded string
4858
 59+ analyzer.generate_chart_data(project,
 60+ collection,
 61+ language_code,
 62+ func,
 63+ time_unit=time_unit,
 64+ cutoff=cutoff,
 65+ cum_cutoff=cum_cutoff)
 66+ except AttributeError, e:
 67+ res = False
 68+ print e #need to capture more fine grained errors but not quite what errors are going to happen.
 69+ except Exception, e:
 70+ res = False
 71+ print e #need to capture more fine grained errors but not quite what errors are going to happen.
 72+
 73+ return res
 74+
 75+
4976 def launcher():
 77+ '''
 78+ This is the main entry point, it creates a queue with jobs and determines
 79+ the type of job and fires it off
 80+ '''
5081 mongo = db.init_mongo_db('wikilytics')
5182 coll = mongo['jobs']
5283 tasks = []
53 - #'in_progress': False}
54 - jobs = coll.find({'finished': False, 'in_progress': False})
 84+ jobs = coll.find({'finished': False, 'in_progress': False, 'error': False})
5585 for job in jobs:
5686 tasks.append(job)
5787
5888 for task in tasks:
5989 if task['jobtype'] == 'dataset':
60 - launch_editor_trends_toolkit(task)
61 - elif task['jobtype'] == 'chart':
62 - launch_chart(task)
 90+ print 'Launching the Editor Trends Analytics Toolkit.'
 91+ res = launch_editor_trends_toolkit(task)
 92+ #res = False
 93+ else:
 94+ print 'Launching %s.' % task['jobtype']
 95+ res = launch_chart(task)
6396
 97+ if res:
 98+ coll.update({'_id': task['_id']}, {'$set': {'finished': True}})
 99+ else:
 100+ '''
 101+ To prevent jobs from recurring non-stop, set error to True. These
 102+ jobs will be excluded and need to be investigated to see what's
 103+ happening.
 104+ '''
 105+ coll.update({'_id': task['_id']}, {'$set': {'error': True}})
 106+
 107+
64108 def debug():
65 - project = 'wiki'
66 - language = 'en'
67 - #launch_editor_trends_toolkit(project, language)
68109 launcher()
69110
 111+
70112 if __name__ == '__main__':
71113 debug()

Status & tagging log