Skip to content

Commit

Permalink
feat: include message_id in emitted worker events
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Jerome <jajerome@redhat.com>
  • Loading branch information
DuckBoss committed May 5, 2023
1 parent c417f4f commit cd3f6a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions worker/echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
var sleepTime time.Duration

// echo opens a new dbus connection and calls the
// com.redhat.Yggdrasil1.Dispatcher1.Transmit method, returning the metadata and
// data it received.
// com.redhat.Yggdrasil1.Dispatcher1.Transmit method, returning the
// metadata, data, and the message id it received.
func echo(w *worker.Worker, addr string, id string, responseTo string, metadata map[string]string, data []byte) error {
if err := w.EmitEvent(ipc.WorkerEventNameWorking, fmt.Sprintf("echoing %v", data)); err != nil {
if err := w.EmitEvent(ipc.WorkerEventNameWorking, fmt.Sprintf("echoing %v", data), id); err != nil {
return fmt.Errorf("cannot call EmitEvent: %w", err)
}

Expand Down
10 changes: 5 additions & 5 deletions worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ func (w *Worker) Transmit(addr string, id string, responseTo string, metadata ma
return
}

// EmitEvent emits a WorkerEvent, including an optional message.
func (w *Worker) EmitEvent(event ipc.WorkerEventName, message string) error {
args := []interface{}{event}
// EmitEvent emits a WorkerEvent, worker message id, and an optional message.
func (w *Worker) EmitEvent(event ipc.WorkerEventName, message string, message_id string) error {
args := []interface{}{event, message_id}
if message != "" {
args = append(args, message)
}
Expand All @@ -178,15 +178,15 @@ func (w *Worker) dispatch(addr string, id string, responseTo string, metadata ma
log.Tracef("metadata = %#v", metadata)
log.Tracef("data = %v", data)

if err := w.EmitEvent(ipc.WorkerEventNameBegin, ""); err != nil {
if err := w.EmitEvent(ipc.WorkerEventNameBegin, "", id); err != nil {
return dbus.NewError("com.redhat.Yggdrasil1.Worker1.EventError", []interface{}{err.Error()})
}

go func() {
if err := w.rx(w, addr, id, responseTo, metadata, data); err != nil {
log.Errorf("cannot call rx: %v", err)
}
if err := w.EmitEvent(ipc.WorkerEventNameEnd, ""); err != nil {
if err := w.EmitEvent(ipc.WorkerEventNameEnd, "", id); err != nil {
log.Errorf("cannot emit event: %v", err)
}
}()
Expand Down

0 comments on commit cd3f6a0

Please sign in to comment.