How can I fail wp_action_scheduler cron job without site break?

Viewed 17

Wp action-scheduler job is running successfully but I want it to fail when any exception comes in the code.

    try {
  $records = some records in array;
  foreach ($records as $r) {
    $sku = $r["SKU"] ?? null;
    if (!isset($sku)) {
     throw new \Exception("SKU is missing");
     return;
    }

    $product_id = Wp::wc_get_product_id_by_sku($sku);
    Wp::update_post_meta($product_id, "_regular_price", 500);
   }
} catch (\Exception $e) {
  echo($e);
  **//Here I want to fail the action scheduler job**
  return false;
}

In my case, everything works correctly but it should be failed schedule job if comes into catch (\Exception $e){---} without site break.

0 Answers
Related