Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-23T13:37:52.433Z
Answers.Text: Is there something I can do then?
Answers.UserDisplayName: Nancy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-23T17:11:02.840Z
Answers.Text: You can look into increasing your web server’s max allowed connections.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-20T19:43:58.090Z
Answers.LastActivityDate: 2020-01-20T19:43:58.090Z
Answers.UserDisplayName: Brandon Kelly
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-04T18:57:55.803Z
Answers.Text: 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?
Answers.UserDisplayName: Nancy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-04T20:01:38.683Z
Answers.Text: Ahhh sorry, just noticed that you are talking about Craft 2, not 3.
Answers.UserDisplayName: Arjan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-04T09:30:58.227Z
Answers.LastActivityDate: 2020-01-04T09:30:58.227Z
Answers.UserDisplayName: Arjan
Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-01-05T03:55:56.910Z
Comments.Text: @BradBell Do you have an idea?
Comments.UserDisplayName: Nancy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-01-18T16:50:05.700Z
Comments.Text: What is the `totalSteps` value getting set to in the database? And, are you using subtasks at all – or just one parent task?
Comments.UserDisplayName: Brandon Kelly
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-01-20T13:25:30.047Z
Comments.Text: @BrandonKelly totalSteps in database is 864, no substasks, just one parent task.
Comments.UserDisplayName: Nancy
Tags: <craft2><tasks>
Title: Craft CMS 2 Task progression
ThreadText: # 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**: @username_1 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.  
  
  ---
  
  