Note that there are some explanatory texts on larger screens.

plurals
  1. POProcessing a list with queued tasks. How to make sure each value in the list is used once and only once?
    primarykey
    data
    text
    <p>I'm using app engine with python</p> <p>I have daily tasks to do on a list of values. These values are stored in a 'project' value under the targets property:</p> <pre><code>myproject1.targets=['foo','bar','foo2','bar2','foo3','bar3','foo4','bar4','foo5','bar5'] </code></pre> <p>My goal is to enqueue a call to the url: <code>url_to_my_worker</code> for each value, with the value as a parameter.</p> <p>I currently only have one project object in my database.</p> <p>I run schedule_daily_projects_tasks which basically enqueues schedule_daily_profile_tasks for each profile object</p> <pre><code>class schedule_daily_projects_tasks(webapp.RequestHandler): def post(self): key=self.request.get('key') pro=project.get(key) profiles=my_profile.gql("WHERE project=:1",pro) logging.info(profiles) for profile in profiles: taskqueue.add(url='/control/schedule_daily_profile_tasks', params={'key': profile.key()}) </code></pre> <p>Then runs 'schedule_daily_profile_tasks' for every profile. </p> <pre><code>class schedule_daily_profile_tasks(webapp.RequestHandler): def post(self): key=self.request.get('key') profile=my_profile.get(key) pro=profile.project for i in range(1, 6): now=datetime.now() tim=datetime(year=now.year, month=now.month, day=now.day, hour=8+i) screen_name=pro.targets.pop() taskqueue.add(url='/url_to_my_worker', params={'profk': key, 'screen_name':screen_name}, eta=tim) pro.put() </code></pre> <p>Let's say I have 5 profile objects in my database: profile1 to profile5 So if everything goes wells, I should have 5 tasks enqueued to the url '/url_to_my_worker', with parameters:</p> <pre><code>1) params={'profk': profile1.key(), 'screen_name':'bar5'} 2) params={'profk': profile2.key(), 'screen_name':'foo5'} 3) params={'profk': profile3.key(), 'screen_name':'bar4'} 4) params={'profk': profile4.key(), 'screen_name':'foo4'} 5) params={'profk': profile5.key(), 'screen_name':'bar3'} </code></pre> <p>But instead, I get:</p> <pre><code>1) params={'profk': profile1.key(), 'screen_name':'bar5'} 2) params={'profk': profile2.key(), 'screen_name':'bar5'} 3) params={'profk': profile3.key(), 'screen_name':'bar5'} 4) params={'profk': profile4.key(), 'screen_name':'bar5'} 5) params={'profk': profile5.key(), 'screen_name':'bar5'} </code></pre> <p>I believe the tasks run too fast, so n°2 starts before n°1 has "popped". Therefore myproject1.targets has the same value.</p> <p>How to make sure each value in the list is used once and only once?</p> <p>Many Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload