feat: add pre-commit hooks & refactor code to pass linting
This commit is contained in:
@ -3,8 +3,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/magefile/mage/mage"
|
||||
"os"
|
||||
|
||||
"github.com/magefile/mage/mage"
|
||||
)
|
||||
|
||||
func main() { os.Exit(mage.Main()) }
|
||||
|
@ -1,56 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/RichardKnop/machinery/v1"
|
||||
"github.com/RichardKnop/machinery/v1/config"
|
||||
"github.com/RichardKnop/machinery/v1/tasks"
|
||||
)
|
||||
|
||||
func Add(args ...int64) (int64, error) {
|
||||
sum := int64(0)
|
||||
for _, arg := range args {
|
||||
sum += arg
|
||||
}
|
||||
return sum, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
var cnf = &config.Config{
|
||||
Broker: "amqp://guest:guest@localhost:5672/",
|
||||
DefaultQueue: "machinery_tasks",
|
||||
ResultBackend: "memcache://localhost:11211",
|
||||
AMQP: &config.AMQPConfig{
|
||||
Exchange: "machinery_exchange",
|
||||
ExchangeType: "direct",
|
||||
BindingKey: "machinery_task",
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Println("starting server")
|
||||
server, err := machinery.NewServer(cnf)
|
||||
if err != nil {
|
||||
// do something with the error
|
||||
}
|
||||
|
||||
addTask0 := tasks.Signature{
|
||||
Name: "userRegistration",
|
||||
Args: []tasks.Arg{
|
||||
{
|
||||
Type: "string",
|
||||
Value: "21345076-6423-4a00-a6bd-cd9f830e2764",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
asyncResult, err := server.SendTask(&addTask0)
|
||||
if err != nil {
|
||||
fmt.Errorf("Could not send task: %s", err.Error())
|
||||
}
|
||||
fmt.Println(asyncResult.GetState())
|
||||
|
||||
// results, err := asyncResult.Get(time.Duration(time.Millisecond * 5))
|
||||
// fmt.Printf("split([\"foo\"]) = %v\n", tasks.HumanReadableResults(results))
|
||||
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/RichardKnop/machinery/v1"
|
||||
"github.com/RichardKnop/machinery/v1/config"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/jordanknott/taskcafe/pg"
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
type MachineTasks struct {
|
||||
Repository pg.Repository
|
||||
}
|
||||
|
||||
func (m *MachineTasks) UserRegistration(userID string) (bool, error) {
|
||||
ctx := context.Background()
|
||||
uid, err := uuid.Parse(userID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
user, err := m.Repository.GetUserAccountByID(ctx, uid)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if user.Username == "jordan" {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
var cnf = &config.Config{
|
||||
Broker: "amqp://guest:guest@localhost:5672/",
|
||||
DefaultQueue: "machinery_tasks",
|
||||
ResultBackend: "memcache://localhost:11211",
|
||||
AMQP: &config.AMQPConfig{
|
||||
Exchange: "machinery_exchange",
|
||||
ExchangeType: "direct",
|
||||
BindingKey: "machinery_task",
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Println("starting server")
|
||||
server, err := machinery.NewServer(cnf)
|
||||
if err != nil {
|
||||
// do something with the error
|
||||
}
|
||||
|
||||
db, err := sqlx.Connect("postgres", "user=postgres password=test host=0.0.0.0 dbname=citadel sslmode=disable")
|
||||
repo := pg.NewRepository(db)
|
||||
tasks := MachineTasks{repo}
|
||||
server.RegisterTasks(map[string]interface{}{
|
||||
"userRegistration": tasks.UserRegistration,
|
||||
})
|
||||
|
||||
worker := server.NewWorker("citadel_worker", 10)
|
||||
fmt.Println("launching worker")
|
||||
err = worker.Launch()
|
||||
if err != nil {
|
||||
// do something with the error
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user