PostgreSQL LISTEN NOTIFY support
Open
Nobody has claimed this yet.
pr:missing usecase
- Dominant language
- PHP
- Stars
- 1.1k
- Forks
- 285
- Avg merge
- 5d 3h
- Merged PRs (30d)
- 2
Description
Instead of db query each timeout seconds
my sux version
<?php
namespace application\modules\queue\components\drivers;
use yii\queue\db\Queue;
class Db extends Queue
{
public $listener = 'queue';
public function run($repeat, $timeout = 0)
{
if(!$repeat) {
return parent::run($repeat, $timeout);
}
$this->db->createCommand("LISTEN {$this->listener}")->execute();
return $this->runWorker(function (callable $canContinue) use ($repeat, $timeout) {
$first = true;
while($canContinue()) {
if(!$first) {
$notify = $this->db->pdo->pgsqlGetNotify();
if(!$notify) {
sleep($timeout);
continue;
}
}
$first = false;
while(true) {
if ($payload = $this->reserve() and $this->handleMessage(
$payload['id'],
$payload['job'],
$payload['ttr'],
$payload['attempt']
)) {
$this->release($payload);
continue;
}
break;
}
}
});
}
public function push($job)
{
$id = parent::push($job);
$this->notify($id);
return $id;
}
public function notify($payload)
{
$payload = serialize($payload);
$this->db->createCommand("NOTIFY {$this->listener}, '$payload'")->execute();
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the PHP example in the issue and compare its LISTEN/NOTIFY flow with the repository's existing database queue worker and polling behavior. Define how PostgreSQL notification support should interact with repeated workers, job pushing, and payload delivery; done should mean the database queue can react to notifications without polling delays.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, postgresql
- Domain
- backend, database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100