busy('worker_tick'); try { $worked = $worker->tick(); $errors = $worker->observationErrors(); } catch (\Throwable $error) { $errors[] = 'worker_tick_failed'; $heartbeat->error('worker_tick_failed'); fwrite(STDERR, 'cloud worker temporarily unavailable: ' . get_class($error) . PHP_EOL); if ($once) { return 1; } $worked = false; } if ($errors !== []) { $heartbeat->error($errors[0]); } // SMTP remains isolated from lifecycle and policy workers. if (!$policyOnly) { $errors = array_merge($errors, self::deliverNotifications($heartbeat)); } if ($errors === []) { $heartbeat->success(); } else { $heartbeat->error($errors[0]); } if (!$once && !$worked) { usleep(1000000); } } while (!$once); } catch (\Throwable $error) { $heartbeat->error('worker_tick_failed'); throw $error; } finally { $heartbeat->stopped(); } return 0; } private static function deliverNotifications(CloudRuntimeHeartbeat $heartbeat): array { $heartbeat->busy('notification'); try { CloudInvoiceService::deliverReminders(1); return CloudInvoiceService::observationErrors('notifications'); } catch (\Throwable $error) { fwrite(STDERR, 'cloud notification mail temporarily unavailable: ' . get_class($error) . PHP_EOL); return ['notification_failed']; } } }