Skip to content

Commit

Permalink
- [add]LogEventChannelReady and its derived struct `LogEventChannel…
Browse files Browse the repository at this point in the history
…InputReady` and `LogEventChannelOutputReady`, and its test case.

- [chg]README.md: add donation and other badges.
  • Loading branch information
vistart committed Jan 17, 2024
1 parent 4e3b53e commit a6b5eef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
A framework developed in Go that manages the execution of workflows described by directed acyclic graphs.

[![Go Reference](https://pkg.go.dev/badge/github.com/rhosocial/go-dag.svg)](https://pkg.go.dev/github.com/rhosocial/go-dag)
![GitHub Tag](https://img.shields.io/github/v/tag/rhosocial/go-dag)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/rhosocial/go-dag)
[![Go Report Card](https://goreportcard.com/badge/github.com/rhosocial/go-dag)](https://goreportcard.com/report/github.com/rhosocial/go-dag)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/rhosocial/go-dag/go.yml?branch=r1.0)

## Introduction

Expand All @@ -17,4 +20,12 @@ Currently, the released versions include:

## Reference

For more details, please visit [this](https://docs.go-dag.dev.rho.social/).
For more details, please visit [this](https://docs.go-dag.dev.rho.social/).

If you want guidance on how to use it, you can:

[![Gitter](https://img.shields.io/gitter/room/rhosocial/go-dag)](https://matrix.to/#/#go-dag.rhosocial:gitter.im)

If you want guidance on using this framework to transform your complex tasks into the most efficient workflows, you can start by donating to:

[![Donate](https://liberapay.com/assets/widgets/donate.svg)](https://liberapay.com/vistart/donate)
2 changes: 1 addition & 1 deletion workflow/simple/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ func (d *DAG[TInput, TOutput]) BuildWorkflowInput(ctx context.Context, result an
i := i
go func() {
if chs[i] != nil {
chs[i] <- result
d.Log(ctx, LogEventChannelInputReady{LogEventChannelReady{value: result, name: inputs[i]}})
chs[i] <- result
}
}()
}
Expand Down
13 changes: 6 additions & 7 deletions workflow/simple/dag_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ func (l LogEventChannelReady) Value() any {
return l.value
}

func (l LogEventChannelReady) Name() string { return l.name }

func (l LogEventChannelReady) Level() LogLevel { return LevelDebug }

func (l LogEventChannelReady) Message() string {
Expand All @@ -205,11 +207,9 @@ type LogEventChannelInputReady struct {
LogEventChannelReady
}

func (l LogEventChannelInputReady) Name() string { return "->:" + l.name }

func (l LogEventChannelInputReady) Message() string {
if l.message == "" {
return "injected"
return "->:channel"
}
return l.message
}
Expand All @@ -219,11 +219,9 @@ type LogEventChannelOutputReady struct {
LogEventChannelReady
}

func (l LogEventChannelOutputReady) Name() string { return "<-:" + l.name }

func (l LogEventChannelOutputReady) Message() string {
if l.message == "" {
return "received"
return "<-:channel"
}
return l.message
}
Expand Down Expand Up @@ -271,6 +269,7 @@ func (l *Logger) SetFlags(flags uint) {
}

func (l *Logger) logEvent(ctx context.Context, event LogEventInterface) {
now := time.Now().Format(l.params.TimestampFormat)
if !l.params.logDebugEnabled && (event.Level() == LevelDebug) {
return
}
Expand All @@ -283,7 +282,7 @@ func (l *Logger) logEvent(ctx context.Context, event LogEventInterface) {
color = red
std = os.Stderr
}
fmt.Fprintf(std, "[GO-DAG] %v |%s %10s %s| %s\n", time.Now().Format(l.params.TimestampFormat), color, event.Name(), reset, event.Message())
fmt.Fprintf(std, "[GO-DAG] %v |%s %10s %s| %s\n", now, color, event.Name(), reset, event.Message())
}

func (l *Logger) Log(ctx context.Context, events ...LogEventInterface) {
Expand Down

0 comments on commit a6b5eef

Please sign in to comment.