【问题标题】:GAE taskqueue access application storageGAE任务队列访问应用存储
【发布时间】:2013-10-22 20:30:24
【问题描述】:

我的 GAE 应用程序是用 Python 和 webapp2 编写的。我的应用程序旨在分析用户的在线社交网络。用户可以登录并授权我的应用程序,因此将存储访问令牌以进一步抓取数据。然后我使用任务队列启动后端任务,因为爬取过程非常耗时。但是,当我访问数据存储区以获取访问令牌时,我可以获得它。我想知道是否有办法访问前端的数据,而不是任务队列的临时存储。

处理来自用户的http请求的处理程序

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    

【问题讨论】:

  • 这应该是“不能”吗? “当我访问数据存储区以获取访问令牌时,我可以获得它。”
  • 你在哪里创建任务?你确定它有uid 参数吗? CrawlWorker 中的 debug 调用的输出是什么?

标签: google-app-engine


【解决方案1】:

这个问题不清楚(可以还是不能?)但是如果你想从任务队列中访问前端数据,把它作为参数传递给任务队列。

【讨论】:

  • 它准确地回答了它被问到的问题。维持你的 cmets。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-19
  • 1970-01-01
  • 2011-07-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多