Search code examples
phpgoogle-app-enginegoogle-tasks

Adding an Array of Tasks (PHP App Engine)


I have a foreach loop that goes through a list, and for each item on that list, I want to add a task.

Currently I have this:

use google\appengine\api\taskqueue\PushTask;

foreach($list_array as $list)
{
    $list_id = $list['id'];
    $task = new PushTask('/task', ['list_id' => $list_id]);
    $task_name = $task->add();
}

I am assuming it would be a far better move to run the ->add() after all the tasks have been declared. Could anyone give their 2 cents on how I could achieve this or is the way I am doing it fine?


Solution

  • I figured it out. For all who is interested, here is what I did.

    use google\appengine\api\taskqueue\PushTask;
    use google\appengine\api\taskqueue\PushQueue;
    
    $tasks = array();
    
    //find each billable user and add them to a task
    foreach($list_array as $list)
        $tasks[] = new PushTask('/task', ['list_id' => $list_id]);
    
    $queue = new PushQueue();
    $queue->addTasks($tasks);