• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2012 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import time
6
7from appengine_wrappers import taskqueue
8from cron_servlet import CronServlet
9from instance_servlet import InstanceServlet
10from patch_servlet import PatchServlet
11from refresh_servlet import RefreshServlet
12from servlet import Servlet, Request, Response
13from test_servlet import TestServlet
14
15
16_DEFAULT_SERVLET = InstanceServlet.GetConstructor()
17
18
19_FORCE_CRON_TARGET = 'force_cron'
20
21
22_SERVLETS = {
23  'cron': CronServlet,
24  'patch': PatchServlet,
25  'refresh': RefreshServlet,
26  'test': TestServlet,
27}
28
29
30class Handler(Servlet):
31  def Get(self):
32    path = self._request.path
33
34    if path.startswith('_'):
35      servlet_path = path[1:]
36      if not '/' in servlet_path:
37        servlet_path += '/'
38      servlet_name, servlet_path = servlet_path.split('/', 1)
39      if servlet_name == _FORCE_CRON_TARGET:
40        queue = taskqueue.Queue()
41        queue.purge()
42        time.sleep(2)
43        queue.add(taskqueue.Task(url='/_cron'))
44        return Response.Ok('Cron job started.')
45      if servlet_name == 'enqueue':
46        queue = taskqueue.Queue()
47        queue.add(taskqueue.Task(url='/%s'%servlet_path))
48        return Response.Ok('Task enqueued.')
49      servlet = _SERVLETS.get(servlet_name)
50      if servlet is None:
51        return Response.NotFound('"%s" servlet not found' %  servlet_path)
52    else:
53      servlet_path = path
54      servlet = _DEFAULT_SERVLET
55
56    return servlet(Request(servlet_path,
57                           self._request.host,
58                           self._request.headers,
59                           self._request.arguments)).Get()
60