1
0
Fork 0
mirror of synced 2024-07-03 13:41:01 +12:00

Merge pull request #5431 from appwrite/feat-db-pools-event-pause

feature to pause events
This commit is contained in:
Eldad A. Fux 2023-05-15 19:07:47 +01:00 committed by GitHub
commit 662bcaaaf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 0 deletions

View file

@ -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 false;
}
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;
}
}

View file

@ -142,6 +142,10 @@ class Func extends Event
*/
public function trigger(): string|bool
{
if ($this->paused) {
return false;
}
$client = new Client($this->queue, $this->connection);
$events = $this->getEvent() ? Event::generateEvents($this->getEvent(), $this->getParams()) : null;

View file

@ -58,6 +58,14 @@ 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