Skip to content

Commit

Permalink
CORE-9075: actually check in the new source file
Browse files Browse the repository at this point in the history
  • Loading branch information
slr71 committed Aug 3, 2018
1 parent edb1efd commit 6bcda8c
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions publisher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package main

import (
"github.com/cyverse-de/messaging"
)

// JobUpdatePublisher is the interface for types that need to publish a job
// update.
type JobUpdatePublisher interface {
PublishJobUpdate(m *messaging.UpdateMessage) error
Reconnect() error
Close()
}

type DefaultJobUpdatePublisher struct {
uri string
exchange string
client *messaging.Client
}

func newMessagingClient(uri, exchange string, reconnect bool) (*messaging.Client, error) {
client, err := messaging.NewClient(uri, reconnect)
if err != nil {
return nil, err
}

client.SetupPublishing(exchange)

return client, nil
}

func NewDefaultJobUpdatePublisher(uri, exchange string) (*DefaultJobUpdatePublisher, error) {
client, err := newMessagingClient(uri, exchange, true)
if err != nil {
return nil, err
}

publisher := &DefaultJobUpdatePublisher{
uri: uri,
exchange: exchange,
client: client,
}
return publisher, nil
}

func (c *DefaultJobUpdatePublisher) PublishJobUpdate(m *messaging.UpdateMessage) error {
return c.client.PublishJobUpdate(m)
}

func (c *DefaultJobUpdatePublisher) Reconnect() error {
c.client.Close()

client, err := newMessagingClient(c.uri, c.exchange, false)
if err != nil {
return err
}

c.client = client
return nil
}

func (c *DefaultJobUpdatePublisher) Close() {
c.client.Close()
}

0 comments on commit 6bcda8c

Please sign in to comment.