adds scheduling for messaging worker

This commit is contained in:
Prateek Banga
2023-10-09 17:29:26 +05:30
parent a92390dda2
commit a77a212e2c
2 changed files with 33 additions and 8 deletions
+29 -7
View File
@@ -2,12 +2,13 @@
namespace Appwrite\Event;
use Resque;
use Utopia\Database\Document;
use ResqueScheduler;
use Utopia\Database\DateTime;
class Messaging extends Event
{
protected ?string $messageId = null;
private ?string $deliveryTime = null;
public function __construct()
{
@@ -38,17 +39,38 @@ class Messaging extends Event
}
/**
* Executes the event and sends it to the messaging worker.
* Sets Delivery time for the messaging event.
*
* @return string|bool
* @throws \InvalidArgumentException
* @param string $deliveryTime
* @return self
*/
public function trigger(): string|bool
public function setDeliveryTime(string $deliveryTime): self
{
return Resque::enqueue($this->queue, $this->class, [
$this->deliveryTime = $deliveryTime;
return $this;
}
/**
* Returns set Delivery Time for the messaging event.
*
* @return string
*/
public function getDeliveryTime(): string
{
return $this->deliveryTime;
}
/**
* Executes the event and sends it to the messaging worker.
*/
public function trigger(): string | bool
{
ResqueScheduler::enqueueAt(!empty($this->deliveryTime) ? $this->deliveryTime : DateTime::now(), $this->queue, $this->class, [
'project' => $this->project,
'user' => $this->user,
'messageId' => $this->messageId,
]);
return true;
}
}