-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from sylphon/add-event-messages
Add event messages
- Loading branch information
Showing
10 changed files
with
282 additions
and
119 deletions.
There are no files selected for viewing
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package comm | ||
|
||
type ( | ||
// LogChan is a channel for log entries | ||
LogChan chan LogEntry | ||
|
||
// EventChan is a channel for status updates | ||
EventChan chan Event | ||
|
||
// ExitChan is a channel for receiving the final exit value (error or nil) | ||
ExitChan chan error | ||
) |
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,67 @@ | ||
package comm | ||
|
||
// EventType is a type for constants that indicate the type of event reported | ||
type EventType uint8 | ||
|
||
// Event is the type that will be sent over the event channel | ||
type Event interface { | ||
EventType() EventType | ||
Data() map[string]interface{} | ||
} | ||
|
||
const ( | ||
// RequestedEvent is for when a build is initially requested | ||
RequestedEvent EventType = iota | ||
|
||
// BuildEvent is for when a `docker build` command starts | ||
BuildEvent | ||
|
||
// BuildCompletedEvent is for when a `docker build` command completes | ||
BuildCompletedEvent | ||
|
||
// TagEvent is for when a `docker tag` command starts | ||
TagEvent | ||
|
||
// TagCompletedEvent is for when a `docker tag` command finishes | ||
TagCompletedEvent | ||
|
||
// PushEvent is for when a `docker push` command starts | ||
PushEvent | ||
|
||
// PushCompletedEvent is for when a `docker push` command finishes | ||
PushCompletedEvent | ||
|
||
// CompletedEvent is for whe nthe entire build finishes (corresopnds to a RequestedEvent) | ||
CompletedEvent | ||
) | ||
|
||
func (t EventType) String() string { | ||
switch t { | ||
case RequestedEvent: | ||
return "RequestedEvent" | ||
case CompletedEvent: | ||
return "CompletedEvent" | ||
case BuildEvent: | ||
return "BuildEvent" | ||
case BuildCompletedEvent: | ||
return "BuildCompletedEvent" | ||
case TagEvent: | ||
return "TagEvent" | ||
case TagCompletedEvent: | ||
return "TagCompletedEvent" | ||
case PushEvent: | ||
return "PushEvent" | ||
case PushCompletedEvent: | ||
return "PushCompletedEvent" | ||
default: | ||
return "" | ||
} | ||
} | ||
|
||
type event struct { | ||
eventType EventType | ||
data map[string]interface{} | ||
} | ||
|
||
func (e *event) EventType() EventType { return e.eventType } | ||
func (e *event) Data() map[string]interface{} { return e.data } |
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,49 @@ | ||
package comm | ||
|
||
import ( | ||
"github.com/Sirupsen/logrus" | ||
) | ||
|
||
// Reporter is type for sending messages on log and/or status channels | ||
type Reporter struct { | ||
log LogChan | ||
event EventChan | ||
} | ||
|
||
// NewReporter returns a reporter that is initialized with the provided channels | ||
func NewReporter(log LogChan, event EventChan) *Reporter { | ||
return &Reporter{ | ||
log: log, | ||
event: event, | ||
} | ||
} | ||
|
||
// Log - send a log message into the ether | ||
func (r *Reporter) Log(entry *logrus.Entry, message string) { | ||
r.LogLevel(entry, message, logrus.DebugLevel) | ||
} | ||
|
||
// LogLevel - send a log message into the ether, specifying level | ||
func (r *Reporter) LogLevel(entry *logrus.Entry, message string, level logrus.Level) { | ||
entry.Message = message | ||
entry.Level = level | ||
if r.log != nil { | ||
r.log <- NewLogEntry(entry) | ||
} | ||
} | ||
|
||
// EventOptions are the options when telling a Reporter to trigger an event | ||
type EventOptions struct { | ||
EventType EventType | ||
Data map[string]interface{} | ||
} | ||
|
||
// Event notifies the Reporter's EventChan that an event has occurred | ||
func (r *Reporter) Event(opts EventOptions) { | ||
if r.event != nil { | ||
r.event <- &event{ | ||
eventType: opts.EventType, | ||
data: opts.Data, | ||
} | ||
} | ||
} |
Oops, something went wrong.