0
我的GAE應用程序是用Python和webapp2編寫的。我的應用程序的目標是分析用戶的在線社交網絡。用戶可以登錄並授權我的應用程序,因此訪問令牌將被存儲以進一步抓取數據。然後,我使用taskqueue啓動後端任務,因爲爬網過程非常耗時。但是,當我訪問數據存儲以獲取訪問令牌時,我可以得到它。我想知道是否有辦法訪問前端的數據,而不是臨時存儲任務隊列。GAE任務隊列訪問應用程序存儲
處理程序從用戶
class Callback(webapp2.RequestHandler):
def get(self):
global client
global r
code = self.request.get('code')
try:
client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET,redirect_uri=CALLBACK_URL)
r = client.request_access_token(code)
access_token = r.access_token
record = model.getAccessTokenByUid(r.uid)
if record is None or r.access_token != record.accessToken:
# logging.debug("access token stored")
**model.insertAccessToken(long(r.uid), access_token, r.expires_in, "uncrawled", datetime.datetime.now())** #data stored here
session = self.request.environ['beaker.session']
session['uid'] = long(r.uid)
self.redirect(CLUSTER_PAGE % ("true"))
except Exception, e:
logging.error("callback:%s" % (str(e)));
self.redirect(CLUSTER_PAGE % ("false"))
手柄處理所有提交到TASKQUEUE
class CrawlWorker(webapp2.RequestHandler):
def post(self): # should run at most 1/s
uid = self.request.get('uid')
logging.debug("start crawling uid:%s in the backend" % (str(uid)))
global client
global client1
global r
tokenTuple = model.getAccessTokenByUid(uid)
if tokenTuple is None: **#here i always get a None**
logging.error("CounterWorker:oops, authorization token is missed.")
return
這應該是「不能」? 「當我訪問數據存儲區以獲取訪問令牌時,我可以得到它。」 – Greg
你在哪裏創建任務?你確定它有'uid'參數嗎? 'CrawlWorker'中調試調用的輸出是什麼? –