Skip to content

Commit 318da41

Browse files
committed
fix undefined key with queue
1 parent 9faa6f5 commit 318da41

File tree

4 files changed

+11
-28
lines changed

4 files changed

+11
-28
lines changed

services/Core/Jobs/Hm_BaseJob.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ abstract class Hm_BaseJob extends Hm_Queueable implements Hm_Job
99
{
1010
public function __construct(protected array $data = []) {
1111
$this->data = $data;
12+
$this->driver = env('QUEUE_DRIVER');
1213
}
1314
}

services/Core/Notifications/Hm_Notification.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Hm_Notification extends Hm_Queueable implements Hm_Dispatcher
2929
public function __construct($content = '')
3030
{
3131
$this->content = $content;
32+
$this->driver = env('QUEUE_DRIVER');
3233
}
3334
/**
3435
* Notifcations can be sent through multiple channels.
@@ -43,7 +44,7 @@ public function via(): array
4344
public function handle(): void
4445
{
4546
dump("Processing ".self::class);
46-
47+
4748
$this->sendNow();
4849
}
4950
public function failed(): void

services/Core/Notifications/Hm_NotificationDispatcher.php

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,12 @@ class Hm_NotificationDispatcher implements Hm_Factory
3232
*/
3333
public static function send(Hm_Notification $notification): void
3434
{
35-
$channels = $notification->via();
36-
foreach ($channels as $channelName) {
37-
if (isset(self::$channelClasses[$channelName])) {
38-
$channelClass = self::channel($channelName);
39-
$channel = new $channelClass();
40-
if (is_subclass_of($notification, Hm_ShouldQueue::class)) {
41-
$driver = $notification->driver;
42-
$queueDriver = Hm_Container::getContainer()->get('queue.manager')->getDriver($driver);
43-
if ($queueDriver) {
44-
$queueDriver->push($notification);
45-
} else {
46-
throw new \Exception("Queue driver {$driver} not found.");
47-
}
48-
} else {
49-
// Send notification immediately if not queued
50-
$channel->send($notification);
51-
}
52-
} else {
53-
throw new \Exception("Channel {$channelName} is not registered or implemented.");
54-
}
35+
$driver = $notification->driver;
36+
$queueDriver = Hm_Container::getContainer()->get('queue.manager')->getDriver($driver);
37+
if ($queueDriver) {
38+
$queueDriver->push($notification);
39+
} else {
40+
throw new \Exception("Queue driver {$driver} not found.");
5541
}
5642
}
5743

services/Notifications/Hm_NewMailNotification.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,10 @@ class Hm_NewMailNotification extends Hm_Notification implements Hm_ShouldQueue
1111
{
1212
use Hm_Dispatchable, Hm_InteractsWithQueue;
1313

14-
public string $driver = 'redis';
15-
16-
// public function __construct(array $config = [])
17-
// {
18-
// parent::__construct($config);
19-
// }
14+
public string $driver = 'database';
2015

2116
public function via(): array
2217
{
23-
return ['telegram'];//, 'slack', 'telegram','broadcast'
18+
return ['telegram','slack'];//, 'slack', 'telegram','broadcast'
2419
}
2520
}

0 commit comments

Comments
 (0)