Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(955)

Side by Side Diff: chrome/common/extensions/docs/server2/handler.py

Issue 679813004: Docserver: Add _query_commit handler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: documentation Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/common/extensions/docs/server2/app.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import time 5 import time
6 6
7 from appengine_wrappers import taskqueue 7 from appengine_wrappers import taskqueue
8 from commit_tracker import CommitTracker
8 from cron_servlet import CronServlet 9 from cron_servlet import CronServlet
9 from instance_servlet import InstanceServlet 10 from instance_servlet import InstanceServlet
11 from object_store_creator import ObjectStoreCreator
10 from patch_servlet import PatchServlet 12 from patch_servlet import PatchServlet
11 from refresh_servlet import RefreshServlet 13 from refresh_servlet import RefreshServlet
12 from servlet import Servlet, Request, Response 14 from servlet import Servlet, Request, Response
13 from test_servlet import TestServlet 15 from test_servlet import TestServlet
14 16
15 17
16 _DEFAULT_SERVLET = InstanceServlet.GetConstructor() 18 _DEFAULT_SERVLET = InstanceServlet.GetConstructor()
17 19
18 20
19 _FORCE_CRON_TARGET = 'force_cron' 21 class _EnqueueServlet(Servlet):
22 '''This Servlet can be used to manually enqueue tasks on the default
23 taskqueue. Useful for when an admin wants to manually force a specific
24 DataSource refresh, but the refresh operation takes longer than the 60 sec
25 timeout of a non-taskqueue request. For example, you might query
26
27 /_enqueue/_refresh/content_providers/cr-native-client?commit=123ff65468dcafff0
28
29 which will enqueue a task (/_refresh/content_providers/cr-native-client) to
30 refresh the NaCl documentation cache for commit 123ff65468dcafff0.
31
32 Access to this servlet should always be restricted to administrative users.
33 '''
34 def __init__(self, request):
35 Servlet.__init__(self, request)
36
37 def Get(self):
38 queue = taskqueue.Queue()
39 queue.add(taskqueue.Task(url='/%s' % self._request.path,
40 params=self._request.arguments))
41 return Response.Ok('Task enqueued.')
42
43
44 class _QueryCommitServlet(Servlet):
45 '''Provides read access to the commit ID cache within the server. For example:
46
47 /_query_commit/master
48
49 will return the commit ID stored under the commit key "master" within the
50 commit cache. Currently "master" is the only named commit we cache, and it
51 corresponds to the commit ID whose data currently populates the data cache
52 used by live instances.
53 '''
54 def __init__(self, request):
55 Servlet.__init__(self, request)
56
57 def Get(self):
58 object_store_creator = ObjectStoreCreator(start_empty=False)
59 commit_tracker = CommitTracker(object_store_creator)
60 return Response.Ok(commit_tracker.Get(self._request.path).Get())
20 61
21 62
22 _SERVLETS = { 63 _SERVLETS = {
23 'cron': CronServlet, 64 'cron': CronServlet,
65 'enqueue': _EnqueueServlet,
24 'patch': PatchServlet, 66 'patch': PatchServlet,
67 'query_commit': _QueryCommitServlet,
25 'refresh': RefreshServlet, 68 'refresh': RefreshServlet,
26 'test': TestServlet, 69 'test': TestServlet,
27 } 70 }
28 71
29 72
30 class Handler(Servlet): 73 class Handler(Servlet):
31 def Get(self): 74 def Get(self):
32 path = self._request.path 75 path = self._request.path
33 76
34 if path.startswith('_'): 77 if path.startswith('_'):
35 servlet_path = path[1:] 78 servlet_path = path[1:]
36 if not '/' in servlet_path: 79 if not '/' in servlet_path:
37 servlet_path += '/' 80 servlet_path += '/'
38 servlet_name, servlet_path = servlet_path.split('/', 1) 81 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) 82 servlet = _SERVLETS.get(servlet_name)
50 if servlet is None: 83 if servlet is None:
51 return Response.NotFound('"%s" servlet not found' % servlet_path) 84 return Response.NotFound('"%s" servlet not found' % servlet_path)
52 else: 85 else:
53 servlet_path = path 86 servlet_path = path
54 servlet = _DEFAULT_SERVLET 87 servlet = _DEFAULT_SERVLET
55 88
56 return servlet(Request(servlet_path, 89 return servlet(Request(servlet_path,
57 self._request.host, 90 self._request.host,
58 self._request.headers, 91 self._request.headers,
59 self._request.arguments)).Get() 92 self._request.arguments)).Get()
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/app.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698