From b5379f0f0cf0790ac6105045e412ef14117c21fa Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 26 Apr 2023 08:37:38 +0000 Subject: [PATCH 1/6] feature to pause events --- src/Appwrite/Event/Event.php | 23 +++++++++++++++++++++++ src/Appwrite/Event/Func.php | 5 +++++ 2 files changed, 28 insertions(+) diff --git a/src/Appwrite/Event/Event.php b/src/Appwrite/Event/Event.php index 0fecbe0304..c4857c801e 100644 --- a/src/Appwrite/Event/Event.php +++ b/src/Appwrite/Event/Event.php @@ -46,6 +46,7 @@ class Event protected array $context = []; protected ?Document $project = null; protected ?Document $user = null; + protected bool $paused = false; /** * @param string $queue @@ -263,6 +264,10 @@ class Event */ public function trigger(): string|bool { + if($this->paused) { + return; + } + return Resque::enqueue($this->queue, $this->class, [ 'project' => $this->project, 'user' => $this->user, @@ -468,4 +473,22 @@ class Event */ return \array_values($events); } + + /** + * Get the value of paused + */ + public function isPaused(): bool + { + return $this->paused; + } + + /** + * Set the value of paused + */ + public function setPaused(bool $paused): self + { + $this->paused = $paused; + + return $this; + } } diff --git a/src/Appwrite/Event/Func.php b/src/Appwrite/Event/Func.php index 5f8b4c80c6..1b182463c2 100644 --- a/src/Appwrite/Event/Func.php +++ b/src/Appwrite/Event/Func.php @@ -142,6 +142,10 @@ class Func extends Event */ public function trigger(): string|bool { + if($this->paused) { + return; + } + $client = new Client($this->queue, $this->connection); $events = $this->getEvent() ? Event::generateEvents($this->getEvent(), $this->getParams()) : null; @@ -174,6 +178,7 @@ class Func extends Event $this->payload = $event->getPayload(); $this->event = $event->getEvent(); $this->params = $event->getParams(); + $this->paused = $event->isPaused(); return $this; } } From b147cadaa2fe34e2567627c2fcdf9449013c981e Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 26 Apr 2023 08:41:22 +0000 Subject: [PATCH 2/6] don't overwrite the paused state from the event --- src/Appwrite/Event/Func.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Appwrite/Event/Func.php b/src/Appwrite/Event/Func.php index 1b182463c2..5a6dc2157b 100644 --- a/src/Appwrite/Event/Func.php +++ b/src/Appwrite/Event/Func.php @@ -178,7 +178,6 @@ class Func extends Event $this->payload = $event->getPayload(); $this->event = $event->getEvent(); $this->params = $event->getParams(); - $this->paused = $event->isPaused(); return $this; } } From 472265497b7605541699cf4e889596d8da840ec2 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 11 May 2023 06:12:39 +0000 Subject: [PATCH 3/6] fix formatting and error --- src/Appwrite/Event/Event.php | 4 ++-- src/Appwrite/Event/Func.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Event/Event.php b/src/Appwrite/Event/Event.php index c4857c801e..0cf90eb3d3 100644 --- a/src/Appwrite/Event/Event.php +++ b/src/Appwrite/Event/Event.php @@ -264,8 +264,8 @@ class Event */ public function trigger(): string|bool { - if($this->paused) { - return; + if ($this->paused) { + return false; } return Resque::enqueue($this->queue, $this->class, [ diff --git a/src/Appwrite/Event/Func.php b/src/Appwrite/Event/Func.php index 5a6dc2157b..d1ef112b3a 100644 --- a/src/Appwrite/Event/Func.php +++ b/src/Appwrite/Event/Func.php @@ -142,7 +142,7 @@ class Func extends Event */ public function trigger(): string|bool { - if($this->paused) { + if ($this->paused) { return; } From 518c177c230081fbaa881f38e5fe06971271e038 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 11 May 2023 07:51:39 +0000 Subject: [PATCH 4/6] fix error --- src/Appwrite/Event/Func.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Event/Func.php b/src/Appwrite/Event/Func.php index d1ef112b3a..d121b47a4a 100644 --- a/src/Appwrite/Event/Func.php +++ b/src/Appwrite/Event/Func.php @@ -143,7 +143,7 @@ class Func extends Event public function trigger(): string|bool { if ($this->paused) { - return; + return false; } $client = new Client($this->queue, $this->connection); From d9a1ae276125092c5d0e68f958854ec77580684f Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 15 May 2023 00:30:31 +0000 Subject: [PATCH 5/6] paused unit test --- tests/unit/Event/EventTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/unit/Event/EventTest.php b/tests/unit/Event/EventTest.php index dee905638f..465422c44c 100644 --- a/tests/unit/Event/EventTest.php +++ b/tests/unit/Event/EventTest.php @@ -58,6 +58,13 @@ class EventTest extends TestCase $this->assertEquals(\Resque::size($this->queue), 1); } + public function testPause(): void { + $this->object->setPaused(true); + $this->assertTrue($this->object->isPaused()); + $this->object->setPaused(false); + $this->assertNotTrue($this->object->isPaused()); + } + public function testReset(): void { $this->object From 9a358b921a23a6be4c2a201b1e911f55005b601c Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 15 May 2023 00:32:37 +0000 Subject: [PATCH 6/6] fix formatting --- tests/unit/Event/EventTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unit/Event/EventTest.php b/tests/unit/Event/EventTest.php index 465422c44c..a328c8d599 100644 --- a/tests/unit/Event/EventTest.php +++ b/tests/unit/Event/EventTest.php @@ -58,7 +58,8 @@ class EventTest extends TestCase $this->assertEquals(\Resque::size($this->queue), 1); } - public function testPause(): void { + public function testPause(): void + { $this->object->setPaused(true); $this->assertTrue($this->object->isPaused()); $this->object->setPaused(false);