Skip to content

Commit

Permalink
add schedule support
Browse files Browse the repository at this point in the history
Signed-off-by: Toby Yan <me@tobyan.com>
  • Loading branch information
toby1991 committed May 15, 2019
1 parent fbbad3c commit 04b3c4d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
14 changes: 12 additions & 2 deletions app/console/commands/hello.go
Expand Up @@ -14,14 +14,24 @@ type HelloWorld struct {
} }


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


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


func (hw *HelloWorld) Handler(arg *cmd.Arg) error { 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 return nil
} }
6 changes: 6 additions & 0 deletions app/console/schedule.go
@@ -1 +1,7 @@
package console package console

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

func Schedule(schedule *cmd.Schedule) {
schedule.Command("say:hello-world hi,totoval").EverySecond()
}
16 changes: 13 additions & 3 deletions artisan.go
Expand Up @@ -6,14 +6,17 @@ import (


"github.com/urfave/cli" "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/cache"
"github.com/totoval/framework/cmd" "github.com/totoval/framework/cmd"
"github.com/totoval/framework/cmd/failed_queue" "github.com/totoval/framework/cmd/commands/schedule"
"github.com/totoval/framework/cmd/migration"
"github.com/totoval/framework/console"
"github.com/totoval/framework/database" "github.com/totoval/framework/database"
"github.com/totoval/framework/helpers/m" "github.com/totoval/framework/helpers/m"
"github.com/totoval/framework/queue" "github.com/totoval/framework/queue"
app_schedule "totoval/app/console"


"totoval/app/console/commands" "totoval/app/console/commands"


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


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


func main() { func main() {
scheduleInit()

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


} }

func scheduleInit() {
app_schedule.Schedule(cmd.NewSchedule())
}
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -9,7 +9,7 @@ require (
github.com/go-playground/universal-translator v0.16.0 github.com/go-playground/universal-translator v0.16.0
github.com/golang/protobuf v1.3.1 github.com/golang/protobuf v1.3.1
github.com/jinzhu/gorm v1.9.2 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 github.com/ugorji/go/codec v0.0.0-20190204201341-e444a5086c43 // indirect
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd // indirect golang.org/x/net v0.0.0-20190213061140-3a22650c66bd // indirect
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect
Expand Down
12 changes: 7 additions & 5 deletions main.go
Expand Up @@ -4,7 +4,6 @@ import (
"net/http" "net/http"
"reflect" "reflect"
"sync" "sync"
"time"


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

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


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


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


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


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

0 comments on commit 04b3c4d

Please sign in to comment.