-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): implement postgres queue driver (#3030)
- Loading branch information
1 parent
3c9359d
commit dc7789e
Showing
10 changed files
with
1,492 additions
and
60 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package executor | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
) | ||
|
||
type loggerFn func(string, ...any) | ||
|
||
func newLoggerFn(name string) loggerFn { | ||
return func(format string, params ...any) { | ||
log.Printf("[%s] %s", name, fmt.Sprintf(format, params...)) | ||
} | ||
} | ||
|
||
func NewInMemoryQueueDriver(name string) *InMemoryQueueDriver { | ||
return &InMemoryQueueDriver{ | ||
log: newLoggerFn(fmt.Sprintf("InMemoryQueueDriver - %s", name)), | ||
queue: make(chan Job), | ||
exit: make(chan bool), | ||
name: name, | ||
} | ||
} | ||
|
||
type InMemoryQueueDriver struct { | ||
log loggerFn | ||
queue chan Job | ||
exit chan bool | ||
q *Queue | ||
name string | ||
} | ||
|
||
func (qd *InMemoryQueueDriver) SetQueue(q *Queue) { | ||
qd.q = q | ||
} | ||
|
||
func (qd InMemoryQueueDriver) Enqueue(job Job) { | ||
qd.queue <- job | ||
} | ||
|
||
func (qd InMemoryQueueDriver) Start() { | ||
for i := 0; i < QueueWorkerCount; i++ { | ||
go func() { | ||
qd.log("start") | ||
for { | ||
select { | ||
case <-qd.exit: | ||
qd.log("exit") | ||
return | ||
case job := <-qd.queue: | ||
qd.q.Listen(job) | ||
} | ||
} | ||
}() | ||
} | ||
} | ||
|
||
func (qd InMemoryQueueDriver) Stop() { | ||
qd.log("stopping") | ||
qd.exit <- true | ||
} |
Oops, something went wrong.