-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(464): add support for queueing async actions in background
- Loading branch information
Showing
11 changed files
with
413 additions
and
28 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 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,40 @@ | ||
package act | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/redis/go-redis/v9" | ||
"github.com/rs/zerolog" | ||
) | ||
|
||
type IPublisher interface { | ||
Publish(ctx context.Context, payload []byte) error | ||
} | ||
|
||
var _ IPublisher = (*Publisher)(nil) | ||
|
||
type Publisher struct { | ||
Logger zerolog.Logger | ||
RedisDB redis.Cmdable | ||
ChannelName string | ||
} | ||
|
||
func NewPublisher(publisher Publisher) (*Publisher, error) { | ||
if err := publisher.RedisDB.Ping(context.Background()).Err(); err != nil { | ||
publisher.Logger.Err(err).Msg("failed to connect redis") | ||
} | ||
return &Publisher{ | ||
Logger: publisher.Logger, | ||
RedisDB: publisher.RedisDB, | ||
ChannelName: publisher.ChannelName, | ||
}, nil | ||
} | ||
|
||
func (p *Publisher) Publish(ctx context.Context, payload []byte) error { | ||
if err := p.RedisDB.Publish(ctx, p.ChannelName, payload).Err(); err != nil { | ||
p.Logger.Err(err).Str("ChannelName", p.ChannelName).Msg("failed to publish task to redis") | ||
return fmt.Errorf("failed to publish task to redis: %w", err) | ||
} | ||
return nil | ||
} |
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
Oops, something went wrong.