开发者

In the python version of Google App Engine mapreduce, how do you access counters from the done_callback?

I am using Google App Engine mapreduce to analyze some data. I am generating a few counters that I would 开发者_开发知识库like to create a simple Google chart from in my done_callback. How do I access the resulting counters from the callback?

#The map method
def count_created_since(entity):
  now = datetime.datetime.now()
  delta = now-entity.created

  #analyze last 12 weeks
  for x in range(12):
    start = 7*x
    stop = 7*(x+1)

    if delta.days >= start and delta.days < stop:
      #The counters
      yield op.counters.Increment(str(x)+" weeks ago")


def my_callback(request):
  # fetch counter results to create a simple Google chart url


You can access the counter's through a MapreduceState's counter_map attribute.

from mapreduce import model
state = model.MapreduceState.get_by_job_id(your_job_id)
# counters live in state.counters_map

There was a discussion on the mailing list a month or so ago about accessing counters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜