updated code structure

This commit is contained in:
marvzhang
2021-04-29 10:44:46 +08:00
parent 820334753a
commit fd0f6fc37a
12 changed files with 192 additions and 80 deletions

View File

@@ -10,12 +10,12 @@ func init() {
}
var apiCmd = &cobra.Command{
Use: "api",
Short: "Start API server",
Long: `Start API server of Crawlab which serves data to frontend`,
Use: "api",
Aliases: []string{"A"},
Short: "Start API server",
Long: `Start API server of Crawlab which serves data to frontend`,
Run: func(cmd *cobra.Command, args []string) {
api := apps.NewApi()
api.Init()
api.Run()
apps.Start(api)
},
}

View File

@@ -10,13 +10,13 @@ func init() {
}
var handlerCmd = &cobra.Command{
Use: "handler",
Short: "Start task handler",
Long: `Start task handler service (worker) of Crawlab
which runs tasks assigned by master node`,
Use: "handler",
Aliases: []string{"H"},
Short: "Start handler",
Long: `Start a handler instance of Crawlab
which runs tasks with given parameters`,
Run: func(cmd *cobra.Command, args []string) {
handler := apps.NewHandler()
handler.Init()
handler.Run()
apps.Start(handler)
},
}

22
backend/cmd/master.go Normal file
View File

@@ -0,0 +1,22 @@
package cmd
import (
"crawlab/apps"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(masterCmd)
}
var masterCmd = &cobra.Command{
Use: "master",
Aliases: []string{"M"},
Short: "Start master",
Long: `Start a master instance of Crawlab
which runs api and assign tasks to worker nodes`,
Run: func(cmd *cobra.Command, args []string) {
master := apps.NewMaster()
apps.Start(master)
},
}

23
backend/cmd/worker.go Normal file
View File

@@ -0,0 +1,23 @@
package cmd
import (
"crawlab/apps"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(workerCmd)
}
var workerCmd = &cobra.Command{
Use: "worker",
Aliases: []string{"W"},
Short: "Start worker",
Long: `Start a worker instance of Crawlab
serving in the worker node and executes tasks
assigned by the master node`,
Run: func(cmd *cobra.Command, args []string) {
worker := apps.NewWorker()
apps.Start(worker)
},
}