-
Notifications
You must be signed in to change notification settings - Fork 0
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 #4 from Famcache/feature/1.2.2-retry
Feature/1.2.2 retry
- Loading branch information
Showing
38 changed files
with
645 additions
and
292 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.2.2 | ||
1.2.3 |
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 |
---|---|---|
|
@@ -4,5 +4,5 @@ package cache | |
type SetOptions struct { | ||
Key string | ||
Value string | ||
TTL *int64 | ||
TTL *uint64 | ||
} |
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,8 @@ | ||
package command | ||
|
||
type MessagingCommand interface { | ||
ID() string | ||
Type() CommandType | ||
Topic() string | ||
Data() string | ||
} |
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,15 @@ | ||
package command | ||
|
||
import "net" | ||
|
||
type StoreCommand interface { | ||
ID() string | ||
Type() CommandType | ||
Key() string | ||
Value() *string | ||
TTL() *uint64 | ||
|
||
ReplyError(conn net.Conn, response string) | ||
ReplySuccess(conn net.Conn) | ||
ReplyOK(conn net.Conn, response string) | ||
} |
File renamed without changes.
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 |
---|---|---|
@@ -1,6 +1,14 @@ | ||
package pubsub | ||
|
||
import "famcache/domain/command" | ||
|
||
type Message interface { | ||
GetTopic() string | ||
GetData() string | ||
ID() string | ||
Topic() string | ||
Data() string | ||
Recipient() string | ||
CreatedAt() int64 | ||
RetryCount() uint | ||
IncrementRetryCount() | ||
ToMessagingCommand() command.MessagingCommand | ||
} |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package pubsub | ||
|
||
type Queue interface { | ||
Retry(message Message) | ||
Enqueue(message Message) | ||
Remove(messageId string) | ||
Batch() []Message | ||
} |
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,24 @@ | ||
package actor | ||
|
||
func (actor *Actor) ListenFailedMessages() { | ||
for { | ||
<-actor.queueTicker.C | ||
|
||
for _, message := range actor.messagingQueue.Batch() { | ||
peer := actor.peers.GetById(message.Recipient()) | ||
|
||
if peer == nil { | ||
actor.messagingQueue.Remove(message.ID()) | ||
continue | ||
} | ||
|
||
err := actor.Publish(peer, message.ToMessagingCommand()) | ||
|
||
if err == nil { | ||
actor.messagingQueue.Remove(message.ID()) | ||
} else { | ||
message.IncrementRetryCount() | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,23 +1,23 @@ | ||
package actor | ||
|
||
import ( | ||
"famcache/pkg/server/command" | ||
"famcache/domain/command" | ||
"net" | ||
) | ||
|
||
func (actor *Actor) Get(conn net.Conn, query *command.StoreCommand) { | ||
func (actor *Actor) Get(conn net.Conn, query command.StoreCommand) { | ||
sCache := *actor.cache | ||
logger := *actor.logger | ||
|
||
value, err := sCache.Get(query.Key) | ||
value, err := sCache.Get(query.Key()) | ||
|
||
if err != nil { | ||
logger.Error("Error getting key") | ||
|
||
query.ReplyError(conn, err.Error()) | ||
} | ||
|
||
logger.Info("GET", query.Key, value) | ||
logger.Info("GET", query.Key(), value) | ||
|
||
query.ReplyOK(conn, value) | ||
} |
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
package actor | ||
|
||
import ( | ||
"famcache/domain/command" | ||
"famcache/domain/connection" | ||
"famcache/pkg/server/command" | ||
) | ||
|
||
func (actor *Actor) Subscribe(peer connection.Peer, query *command.MessagingCommand) { | ||
func (actor *Actor) Subscribe(peer connection.Peer, query command.MessagingCommand) { | ||
logger := *actor.logger | ||
|
||
logger.Info("Peer" + peer.ID() + " subscribed to the topic: " + query.Topic) | ||
logger.Info("Peer" + peer.ID() + " subscribed to the topic: " + query.Topic()) | ||
|
||
sub := peer.Subscriptions() | ||
|
||
sub.Add(query.Topic) | ||
sub.Add(query.Topic()) | ||
} |
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
package actor | ||
|
||
import ( | ||
"famcache/domain/command" | ||
"famcache/domain/connection" | ||
"famcache/pkg/server/command" | ||
) | ||
|
||
func (actor *Actor) Unsubscribe(peer connection.Peer, query *command.MessagingCommand) { | ||
func (actor *Actor) Unsubscribe(peer connection.Peer, query command.MessagingCommand) { | ||
logger := *actor.logger | ||
|
||
logger.Info("Peer" + peer.ID() + " unsubscribed from topic " + query.Topic) | ||
logger.Info("Peer" + peer.ID() + " unsubscribed from topic " + query.Topic()) | ||
|
||
sub := peer.Subscriptions() | ||
|
||
sub.Remove(query.Topic) | ||
sub.Remove(query.Topic()) | ||
} |
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,61 @@ | ||
package command | ||
|
||
import ( | ||
"famcache/domain" | ||
"famcache/domain/command" | ||
"strings" | ||
) | ||
|
||
var strToCommandType = map[string]command.CommandType{ | ||
"GET": command.CommandGet, | ||
"SET": command.CommandSet, | ||
"DELETE": command.CommandDelete, | ||
"PUBLISH": command.CommandPublish, | ||
"SUBSCRIBE": command.CommandSubscribe, | ||
"UNSUBSCRIBE": command.CommandUnsubscribe, | ||
} | ||
|
||
type AbstractCommand struct { | ||
cType command.CommandType | ||
query string | ||
} | ||
|
||
func (c *AbstractCommand) ToStoreCommand() command.StoreCommand { | ||
return NewStoreCommand(c.cType, c.query) | ||
} | ||
|
||
func (c *AbstractCommand) ToPubsubCommand() command.MessagingCommand { | ||
return NewPubsubCommand(c.cType, c.query) | ||
} | ||
|
||
func (c *AbstractCommand) IsStoreCommand() bool { | ||
return c.cType == command.CommandSet || c.cType == command.CommandGet || c.cType == command.CommandDelete | ||
} | ||
|
||
func (c *AbstractCommand) IsMessagingCommand() bool { | ||
return c.cType == command.CommandPublish || c.cType == command.CommandSubscribe || c.cType == command.CommandUnsubscribe | ||
} | ||
|
||
func determineCommandType(query string) (command.CommandType, bool) { | ||
parts := strings.Fields(strings.TrimSpace(query)) | ||
|
||
if len(parts) < 2 { | ||
return command.CommandGet, false | ||
} | ||
|
||
t, ok := strToCommandType[strings.TrimSpace(strings.ToUpper((parts[1])))] | ||
return t, ok | ||
} | ||
|
||
func NewCommand(query string) (*AbstractCommand, error) { | ||
commandType, ok := determineCommandType(query) | ||
|
||
if !ok { | ||
return nil, domain.ErrUnableToProcessRequest | ||
} | ||
|
||
return &AbstractCommand{ | ||
cType: commandType, | ||
query: query, | ||
}, nil | ||
} |
Oops, something went wrong.