fix nil pointer

This commit is contained in:
2024-04-24 11:10:42 +02:00
parent 83f6444df2
commit 01c327d308

View File

@@ -16,7 +16,7 @@ type MessageQueue struct {
// By default it will be created with a size equals to nthe number of logical // By default it will be created with a size equals to nthe number of logical
// CPU cores. // CPU cores.
// The queue size can be set via the qs flag. // The queue size can be set via the qs flag.
func NewMessageQueue(logger *slog.Logger) *MessageQueue { func NewMessageQueue(l *slog.Logger) *MessageQueue {
size := config.Instance().QueueSize size := config.Instance().QueueSize
if size <= 0 { if size <= 0 {
@@ -26,7 +26,7 @@ func NewMessageQueue(logger *slog.Logger) *MessageQueue {
return &MessageQueue{ return &MessageQueue{
producerCh: make(chan *Process, size), producerCh: make(chan *Process, size),
consumerCh: make(chan struct{}, size), consumerCh: make(chan struct{}, size),
logger: logger, logger: l,
} }
} }
@@ -34,11 +34,12 @@ func NewMessageQueue(logger *slog.Logger) *MessageQueue {
func (m *MessageQueue) Publish(p *Process) { func (m *MessageQueue) Publish(p *Process) {
p.SetPending() p.SetPending()
go func() { go func() {
err := p.SetMetadata() if err := p.SetMetadata(); err != nil {
m.logger.Error( m.logger.Error(
"failed to retrieve metadata", "failed to retrieve metadata",
slog.String("err", err.Error()), slog.String("err", err.Error()),
) )
}
}() }()
m.producerCh <- p m.producerCh <- p
} }