我的GAE应用程序是使用webapp2用Python编写的。我的应用程序的目标是分析用户的在线社交网络。用户可以登录并授权我的应用程序,因此将存储访问令牌以进一步爬行数据。然后我使用taskqueue来启动后端任务,因为爬行过程非常耗时。但是,当我访问数据存储区以获取访问令牌时,我可以得到它。我想知道是否有办法访问前端的数据,而不是任务队列的临时存储。
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"))
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
答案 0 :(得分:0)
问题不明确(它可以或不能吗?)但是如果要从任务队列中访问前端数据,请将其作为参数传递给任务队列。