views:

39

answers:

1

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
+1  A: 

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.

Robert Kluin
Thanks, but how do I determine the job_id in the callback? Is it passed in as parameter via the POST to the callback?
Chris
It is passed in as a parameter named `job_id`.
Robert Kluin