Permalink
Browse files

Lazily import job workers

  • Loading branch information...
1 parent bc49c58 commit efaf537a24cf1e1c404895a17d977a0b05273052 @kumar303 kumar303 committed Oct 3, 2011
Showing with 20 additions and 4 deletions.
  1. +0 −4 common/views.py
  2. +12 −0 jobs/views.py
  3. +8 −0 settings.py
View
@@ -60,8 +60,4 @@ def appengine_warmup(request):
log.info("Warming up")
taskqueue.add(url='/api/current_playlist', method='GET')
load_dbconfig_into_memcache()
- # Import jobs to register them.
- # TODO(Kumar) figure out a better way to register job workers
- from playlists import reports
- from traffic_log import views
return HttpResponse("it's getting hot in here")
View
@@ -21,6 +21,7 @@
from datetime import timedelta
import traceback
+from django.conf import settings
from django.utils import simplejson
from django.http import Http404
@@ -31,6 +32,14 @@
log = logging.getLogger()
+def init_jobs():
+ # TODO(Kumar) figure out a better way to register job workers.
+ # This is currently necessary because app warmup isn't fast enough
+ # to catch process restarts.
+ for path in settings.JOB_WORKER_MODULES:
+ __import__(path) # registers the job workers
+
+
def reap_dead_jobs():
q = Job.all().filter("started <",
datetime.datetime.now() - timedelta(days=2))
@@ -39,6 +48,7 @@ def reap_dead_jobs():
def start_job(request):
+ init_jobs()
# TODO(kumar) check for already running jobs
reap_dead_jobs()
job_name = request.POST['job_name']
@@ -59,6 +69,7 @@ def data(request):
def do_job_work(request):
+ init_jobs()
try:
job = Job.get(request.POST['job_key'])
params = request.POST.get('params', '{}')
@@ -88,6 +99,7 @@ def data(request):
def get_job_product(request, job_key):
+ init_jobs()
job = Job.get(job_key)
if job is None:
raise Http404(
View
@@ -136,3 +136,11 @@
NOSE_PLUGINS = [
'nosenicedots.plugin.NiceDots',
]
+
+
+# Each module here defines job workers so they must be imported
+# by the job runner.
+JOB_WORKER_MODULES = [
+ 'playlists.reports',
+ 'traffic_log.views',
+]

0 comments on commit efaf537

Please sign in to comment.