PHP code example of vincenzoraco / again

1. Go to this page and download the library: Download vincenzoraco/again library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vincenzoraco / again example snippets


while (!$this->isSent()) {
    $this->sendEmail();
}

Again::perform(fn(int $i) => $this->sendEmail())
  ->limitTo(3)                                    // Stop after 3 attempts
  ->until(fn(int $i) => !$this->isSent())         // Keep going while email is not sent
  ->execute();

// Keep retrying while the job is still pending
->until(fn(int $i) => $this->job->isPending())

// Keep going while there are items left to process
->until(fn(int $i) => $this->hasItemsLeft())

$action = Again::perform($actionLogic)
  ->limitTo($limit)  // Limit the number of iterations
  ->until($until)    // Keep going while condition returns true
  ->execute();

$stopReason = Again::perform($actionLogic)
  ->limitTo($limit)
  ->until($until)
  ->execute();  // Execute and get the stop reason

// Check the reason for stopping
if ($stopReason === AgainStopReason::MAX_ITERATIONS_REACHED) {
    $this->notifyToSlack(‘Maximum retries reached.’);
    // Handle the case when max iterations are reached
}

if ($stopReason === AgainStopReason::CONDITION_MET) {
    // Handle the case when the condition was met and the loop stopped
}