<p>If <code>totalSteps</code> is getting set correctly, and <code>currentStep</code> 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.</p>

<p>Perhaps calling <code>saveProduct()</code> 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.</p>

CC BY-SA 4.0
2020-01-23T13:37:52.433Z
Is there something I can do then?
Nancy
CC BY-SA 4.0
2020-01-23T17:11:02.840Z
You can look into increasing your web server’s max allowed connections.
Brandon Kelly
CC BY-SA 4.0
2020-01-20T19:43:58.090Z
2020-01-20T19:43:58.090Z
Brandon Kelly
<p>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.</p>

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

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

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

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

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

        // update progress          
        $this-&gt;setProgress($queue, $currentUser++ / $totalUsers);
    }
}
</code></pre>

<p>setProgress is used to update the progress, which will be visible in the CP.</p>

CC BY-SA 4.0
2020-01-04T18:57:55.803Z
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
CC BY-SA 4.0
2020-01-04T20:01:38.683Z
Ahhh sorry, just noticed that you are talking about Craft 2, not 3.
Arjan
CC BY-SA 4.0
2020-01-04T09:30:58.227Z
2020-01-04T09:30:58.227Z
Arjan
<p>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 </p>

<pre><code>craft()-&gt;commerce_products-&gt;saveProduct($product);
</code></pre>

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

CC BY-SA 4.0
2020-01-05T03:55:56.910Z
@BradBell Do you have an idea?
Nancy
CC BY-SA 4.0
2020-01-18T16:50:05.700Z
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
CC BY-SA 4.0
2020-01-20T13:25:30.047Z
@BrandonKelly totalSteps in database is 864, no substasks, just one parent task.
Nancy
<craft2><tasks>
Craft CMS 2 Task progression
# Craft CMS 2 Task progression

(Asked by: username_0 on 2020-01-04)

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?

**Tags:** craft2, tasks
> **Comments:**
> **username_0**: @BradBell Do you have an idea?  
> **username_1**: What is the `totalSteps` value getting set to in the database? And, are you using subtasks at all – or just one parent task?  
> **username_0**: @BrandonKelly totalSteps in database is 864, no substasks, just one parent task.  

---

## 2 answers

### Answer by username_2 on 2020-01-04. Score: 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.

> **Comments:**
> **username_0**: 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?  
> **username_2**: Ahhh sorry, just noticed that you are talking about Craft 2, not 3.  

---

### Answer by username_1 on 2020-01-20. Score: 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.

> **Comments:**
> **username_0**: Is there something I can do then?  
> **username_1**: You can look into increasing your web server’s max allowed connections.  

---

