Skip to content
Permalink
Browse files

add schedule support

Signed-off-by: Toby Yan <me@tobyan.com>
  • Loading branch information...
toby1991 committed May 15, 2019
1 parent fbbad3c commit 04b3c4dd63a020de225af595cf08ce7d944a52c1
Showing with 39 additions and 11 deletions.
  1. +12 −2 app/console/commands/hello.go
  2. +6 −0 app/console/schedule.go
  3. +13 −3 artisan.go
  4. +1 −1 go.mod
  5. +7 −5 main.go
@@ -14,14 +14,24 @@ type HelloWorld struct {
}

func (hw *HelloWorld) Command() string {
return "say:hello-world {test}"
return "say:hello-world {hi}"
}

func (hw *HelloWorld) Description() string {
return "Say Hello"
}

func (hw *HelloWorld) Handler(arg *cmd.Arg) error {
fmt.Println("Hello World")
hi, err := arg.Get("hi")
if err != nil {
return err
}

if hi == nil {
fmt.Println("Hello World")
return nil
}

fmt.Println(*hi)
return nil
}
@@ -1 +1,7 @@
package console

import "github.com/totoval/framework/cmd"

func Schedule(schedule *cmd.Schedule) {
schedule.Command("say:hello-world hi,totoval").EverySecond()
}
@@ -6,14 +6,17 @@ import (

"github.com/urfave/cli"

"github.com/totoval/framework/cmd/commands/failed_queue"
"github.com/totoval/framework/cmd/commands/migration"
"github.com/totoval/framework/console"

"github.com/totoval/framework/cache"
"github.com/totoval/framework/cmd"
"github.com/totoval/framework/cmd/failed_queue"
"github.com/totoval/framework/cmd/migration"
"github.com/totoval/framework/console"
"github.com/totoval/framework/cmd/commands/schedule"
"github.com/totoval/framework/database"
"github.com/totoval/framework/helpers/m"
"github.com/totoval/framework/queue"
app_schedule "totoval/app/console"

"totoval/app/console/commands"

@@ -37,10 +40,13 @@ func init() {

migration.Initialize()
failed_queue.Initialize()
schedule.Initialize()
commands.Initialize()
}

func main() {
scheduleInit()

app := cli.NewApp()
app.Name = "artisan"
app.Usage = "Let's work like an artisan"
@@ -71,3 +77,7 @@ func main() {
}

}

func scheduleInit() {
app_schedule.Schedule(cmd.NewSchedule())
}
2 go.mod
@@ -9,7 +9,7 @@ require (
github.com/go-playground/universal-translator v0.16.0
github.com/golang/protobuf v1.3.1
github.com/jinzhu/gorm v1.9.2
github.com/totoval/framework v0.5.2-hotfix-2
github.com/totoval/framework v0.5.3
github.com/ugorji/go/codec v0.0.0-20190204201341-e444a5086c43 // indirect
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd // indirect
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect
12 main.go
@@ -4,7 +4,6 @@ import (
"net/http"
"reflect"
"sync"
"time"

"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
@@ -14,8 +13,11 @@ import (
c "github.com/totoval/framework/config"
"github.com/totoval/framework/database"
"github.com/totoval/framework/helpers/m"
"github.com/totoval/framework/helpers/zone"
"github.com/totoval/framework/http/middleware"
"github.com/totoval/framework/hub"
"github.com/totoval/framework/queue"

"totoval/app/events"
"totoval/app/jobs"
"totoval/app/listeners"
@@ -64,21 +66,21 @@ func main() {
s := &http.Server{
Addr: ":" + c.GetString("app.port"),
Handler: r,
ReadTimeout: time.Duration(c.GetInt64("app.read_timeout_seconds")) * time.Second,
WriteTimeout: time.Duration(c.GetInt64("app.write_timeout_seconds")) * time.Second,
ReadTimeout: zone.Duration(c.GetInt64("app.read_timeout_seconds")) * zone.Second,
WriteTimeout: zone.Duration(c.GetInt64("app.write_timeout_seconds")) * zone.Second,
MaxHeaderBytes: 1 << 20,
}

//j := &jobs.ExampleJob{}
//j.SetParam(&pbs.ExampleJob{Query: "shit", PageNumber: 111, ResultPerPage: 222})
//j.SetDelay(5 * time.Second)
////j.SetDelay(5 * zone.Second)
//err := job.Dispatch(j)
//fmt.Println(err)

//go job.Process("example-job")
//fmt.Println(queue.Retry(1))

//go hub.On("add-user-affiliation")
go hub.On("add-user-affiliation")

if err := s.ListenAndServe(); err != nil {
panic(err)

0 comments on commit 04b3c4d

Please sign in to comment.
You can’t perform that action at this time.