-
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.
- Infrastructure Now Handles most of the Errors - Added Logger
- Loading branch information
1 parent
b9e2b7e
commit b7f4923
Showing
5 changed files
with
118 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,53 @@ | ||
package main | ||
|
||
import "github.com/leapfrogtechnology/shift/infrastructure/infrastructure" | ||
import ( | ||
"github.com/leapfrogtechnology/shift/infrastructure/infrastructure" | ||
"github.com/leapfrogtechnology/shift/infrastructure/utils" | ||
"github.com/streadway/amqp" | ||
"log" | ||
) | ||
|
||
func main() { | ||
infrastrucuture.InitializeFrontend() | ||
} | ||
func main() { | ||
|
||
conn, err := amqp.Dial(utils.GenerateQueueUrl()) | ||
utils.FailOnError(err, "Failed to Connect to Message Queue") | ||
defer conn.Close() | ||
|
||
ch, err := conn.Channel() | ||
utils.FailOnError(err, "Failed to open a channel") | ||
defer ch.Close() | ||
|
||
q, err := ch.QueueDeclare( | ||
"initialize", // name | ||
false, // durable | ||
false, // delete when usused | ||
false, // exclusive | ||
false, // no-wait | ||
nil, // arguments | ||
) | ||
utils.FailOnError(err, "Failed to declare a queue") | ||
|
||
messages, err := ch.Consume( | ||
q.Name, //name | ||
"", //consumer | ||
true, //autoAck | ||
false, // exclusive | ||
false, //noLocal | ||
false, //noWait | ||
nil, // args | ||
) | ||
forever := make(chan bool) | ||
go func() { | ||
for message := range messages { | ||
log.Printf("Received a message: %s", message.MessageId) | ||
infrastructureInfo, err := infrastrucuture.InitializeFrontend(message.Body) | ||
if err != nil { | ||
utils.LogError(err, "Cannot Init Infrastructure") | ||
} else { | ||
utils.LogOutput(infrastructureInfo) | ||
} | ||
} | ||
}() | ||
utils.LogInfo("[*] Waiting for messages. To exit Press Ctrl+C") | ||
<-forever | ||
} |
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,13 +1,24 @@ | ||
package utils | ||
|
||
import "log" | ||
import ( | ||
"github.com/logrusorgru/aurora" | ||
"log" | ||
) | ||
|
||
func FailOnError(err error, msg string) { | ||
if err != nil { | ||
log.Fatalf("%s: %s", msg, err) | ||
log.Fatalf("Fatal\n%s: %s",aurora.Red(msg), aurora.Red(err)) | ||
} | ||
} | ||
|
||
func LogError(err error, msg string) { | ||
log.Printf("%s: %s", msg, err) | ||
log.Printf("%s: %s", aurora.Red(msg), aurora.Red(err)) | ||
} | ||
|
||
func LogOutput(msg string) { | ||
log.Println(aurora.Cyan(msg)) | ||
} | ||
|
||
func LogInfo(msg string) { | ||
log.Println(aurora.Blue(msg)) | ||
} |
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 utils | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func GenerateQueueUrl() string{ | ||
rabbitUserName := os.Getenv("RABBIT_USERNAME") | ||
rabbitPassword := os.Getenv("RABBIT_PASSWORD") | ||
rabbitHost := os.Getenv("RABBIT_HOST") | ||
rabbitPort := os.Getenv("RABBIT_PORT") | ||
rabbitUrl := fmt.Sprintf("amqp://%s:%s@%s:%s/", rabbitUserName,rabbitPassword,rabbitHost,rabbitPort) | ||
return rabbitUrl | ||
} |
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