echo "port 4000" | redis-server -
redis-cli -r 100 -p 4000 RPUSH resque:queue:slack '{"class":"notifier","args":["This is a test notification"]}'
go run main.go -queues=notifier
http://localhost:6060/debug/pprof/
A notification worker example
echo "port 4000" | redis-server -
redis-cli -r 100 -p 4000 RPUSH resque:queue:slack '{"class":"notifier","args":["This is a test notification"]}'
go run main.go -queues=notifier
http://localhost:6060/debug/pprof/
package main
import (
"github.com/benmanns/goworker"
"fmt"
"time"
"github.com/parnurzeal/gorequest"
)
type Payload struct {
Username string `json:"username,omitempty"`
IconEmoji string `json:"icon_emoji,omitempty"`
Channel string `json:"channel,omitempty"`
Text string `json:"text,omitempty"`
}
func redirectPolicyFunc(req gorequest.Request, via []gorequest.Request) error {
return fmt.Errorf("Incorrect token (redirection)")
}
func send(webhookURL string, proxy string, payload Payload) []error {
request := gorequest.New().Proxy(proxy)
resp, _, err := request.
Post(webhookURL).
RedirectPolicy(redirectPolicyFunc).
Send(payload).
End()
if err != nil {
return err
}
if resp.StatusCode >= 400 {
return []error{fmt.Errorf("Error sending msg. Status: %v", resp.Status)}
}
return nil
}
func notificationFunc(webhookURL string, response chan<- []error) {
payload := Payload{
Text: ":thinking_face:",
Username: "Hexter Bot",
IconEmoji: ":hexter_is_ur_daddy:",
Channel: "#nuclear-testing-sites",
}
response <- send(webhookURL, "", payload)
}
func notificationWorker(queue string, args ...interface{}) error {
webhookURL := "https://hooks.slack.com/services/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"
responseChannel := make(chan []error)
go notificationFunc(webhookURL, responseChannel)
fmt.Printf("From %s, %v\n", queue, args)
err := <- responseChannel
return err[0]
}
func init() {
settings := goworker.WorkerSettings{
URI: "redis://localhost:6379/",
Connections: 100,
Queues: []string{"myqueue", "delimited", "queues"},
UseNumber: true,
ExitOnComplete: false,
Concurrency: 2,
Namespace: "resque:",
Interval: 5.0,
}
goworker.SetSettings(settings)
goworker.Register("MyClass", notificationWorker)
}
func main() {
if err := goworker.Work(); err != nil {
fmt.Println("Error", err)
}
fmt.Printf("Started on %v", time.Now().Format("2006-01-02 15:04:05"))
}
small core with gin API
package main
import (
"github.com/gin-gonic/gin"
)
func notificationWorker(response chan<- int) {
// handle slack notification
response <- 100
}
func main() {
r := gin.Default()
// notification api
r.GET("/notification", func(c *gin.Context) {
responseChannel := make(chan int, 10)
go notificationWorker(responseChannel)
response := <- responseChannel
c.JSON(200, gin.H{
"message": response,
})
close(responseChannel)
})
r.Run() // listen and serve on 0.0.0.0:8080
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.