fix(automations): log skipped sends with cooldown/max reason
Schedule runs that hit cooldown or max-send limits now write a skipped row to automation_sends so admins can see why no SMS was sent. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -23,7 +23,10 @@ class AutomationSender
|
|||||||
|
|
||||||
public function send(Automation $auto, Customer $customer, string $channel, bool $force = false): bool
|
public function send(Automation $auto, Customer $customer, string $channel, bool $force = false): bool
|
||||||
{
|
{
|
||||||
if (! $this->maySend($auto, $customer, $channel, $force)) {
|
$skipReason = $this->skipReason($auto, $customer, $channel, $force);
|
||||||
|
if ($skipReason !== null) {
|
||||||
|
$this->log($auto, $customer, $channel, 'skipped', $skipReason);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,13 +75,18 @@ class AutomationSender
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function maySend(Automation $auto, Customer $customer, string $channel, bool $force = false): bool
|
public function maySend(Automation $auto, Customer $customer, string $channel, bool $force = false): bool
|
||||||
|
{
|
||||||
|
return $this->skipReason($auto, $customer, $channel, $force) === null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function skipReason(Automation $auto, Customer $customer, string $channel, bool $force = false): ?string
|
||||||
{
|
{
|
||||||
if (! $auto->usesChannel($channel)) {
|
if (! $auto->usesChannel($channel)) {
|
||||||
return false;
|
return 'کانال غیرفعال';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($force) {
|
if ($force) {
|
||||||
return true;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$max = $auto->max_sends;
|
$max = $auto->max_sends;
|
||||||
@@ -90,7 +98,7 @@ class AutomationSender
|
|||||||
->where('status', 'sent')
|
->where('status', 'sent')
|
||||||
->count();
|
->count();
|
||||||
if ($count >= (int) $max) {
|
if ($count >= (int) $max) {
|
||||||
return false;
|
return 'حداکثر ارسال برای این مشتری';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,11 +112,11 @@ class AutomationSender
|
|||||||
->where('created_at', '>=', now()->subHours($cooldown))
|
->where('created_at', '>=', now()->subHours($cooldown))
|
||||||
->exists();
|
->exists();
|
||||||
if ($recent) {
|
if ($recent) {
|
||||||
return false;
|
return "فاصلهٔ حداقل {$cooldown} ساعت از آخرین ارسال";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function ensureAppNameFooter(string $message): string
|
private function ensureAppNameFooter(string $message): string
|
||||||
|
|||||||
Reference in New Issue
Block a user