forked from mattermost/mattermost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobserver.go
64 lines (51 loc) · 1.54 KB
/
jobserver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package main
import (
"os"
"os/signal"
"syscall"
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/mattermost-server/store"
"github.com/mattermost/mattermost-server/store/sqlstore"
"github.com/spf13/cobra"
)
var jobserverCmd = &cobra.Command{
Use: "jobserver",
Short: "Start the Mattermost job server",
Run: jobserverCmdF,
}
func init() {
jobserverCmd.Flags().Bool("nojobs", false, "Do not run jobs on this jobserver.")
jobserverCmd.Flags().Bool("noschedule", false, "Do not schedule jobs from this jobserver.")
}
func jobserverCmdF(cmd *cobra.Command, args []string) {
// Options
noJobs, _ := cmd.Flags().GetBool("nojobs")
noSchedule, _ := cmd.Flags().GetBool("noschedule")
// Initialize
a, err := initDBCommandContext("config.json")
if err != nil {
panic(err.Error())
}
defer l4g.Close()
a.Jobs.Store = store.NewLayeredStore(sqlstore.NewSqlSupplier(a.Metrics), a.Metrics, a.Cluster)
defer a.Jobs.Store.Close()
a.Jobs.LoadLicense()
// Run jobs
l4g.Info("Starting Mattermost job server")
if !noJobs {
a.Jobs.StartWorkers()
}
if !noSchedule {
a.Jobs.StartSchedulers()
}
var signalChan chan os.Signal = make(chan os.Signal)
signal.Notify(signalChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
<-signalChan
// Cleanup anything that isn't handled by a defer statement
l4g.Info("Stopping Mattermost job server")
a.Jobs.StopSchedulers()
a.Jobs.StopWorkers()
l4g.Info("Stopped Mattermost job server")
}