1

In Craft CMS 2, I've created a task for updating Craft Commerce products from an Excel file. Everything's working correctly except the UI progression bar. The progression bar in control panel stays at 0 %, even if in database, I see steps increasing. Then when task is finished, it goes directly to the end (100 %) and disappear. I noticed that it will happen if I call for

craft()->commerce_products->saveProduct($product);

If I comment this line, progression works correctly. Any idea on what's going wrong?

  • @BradBell Do you have an idea? – Nancy Jan 5 at 3:55
  • What is the totalSteps value getting set to in the database? And, are you using subtasks at all – or just one parent task? – Brandon Kelly Jan 18 at 16:50
  • @BrandonKelly totalSteps in database is 864, no substasks, just one parent task. – Nancy Jan 20 at 13:25
1

As far as I know you should manually set the progress value. The task can't determine the progress by itself, unless you are returning/polling this data.

An example of how we use it, for sending activation mails to multiple users;

public function execute($queue)
{   
    // creation date of user        
    $days = ($this->data['creationDate']) ? $this->data['creationDate'] : 7;

    // get pending users
    $dateFilter = (new \DateTime( $days . ' days ago'))->format(\DateTime::ATOM);
    $users = \craft\elements\User::find()->status('pending')->dateCreated(" < {$dateFilter}")->all();

    // loop
    $totalUsers = count($users);
    $currentUser = 0;   

    foreach($users as $user) {          
        // send mail
        $result = $this->sendReminderMail($user);

        // update progress          
        $this->setProgress($queue, $currentUser++ / $totalUsers);
    }
}

setProgress is used to update the progress, which will be visible in the CP.

| improve this answer | |
  • The progress value should increments automatically. Also, there are no setProgress function, so it seems it's custom. Your execute function is in the task itself? – Nancy Jan 4 at 18:57
  • Ahhh sorry, just noticed that you are talking about Craft 2, not 3. – Arjan Jan 4 at 20:01
0

If totalSteps is getting set correctly, and currentStep is getting updated correctly, yet the progress bar isn’t progressing, then it’s likely happening because the server’s connections are maxed out, so the Ajax request that is trying to get the new progress for the Control Panel isn’t getting resolved.

Perhaps calling saveProduct() is ultimately resulting in the server attempting to make its own HTTP request to itself – the SEOmatic plugin tends to do that, for example – which is blocking the Control Panel from making additional HTTP requests to the web server.

| improve this answer | |
  • Is there something I can do then? – Nancy Jan 23 at 13:37
  • You can look into increasing your web server’s max allowed connections. – Brandon Kelly Jan 23 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.