本文整理匯總了Golang中github.com/facette/facette/pkg/worker.Worker.Shutdown方法的典型用法代碼示例。如果您正苦於以下問題:Golang Worker.Shutdown方法的具體用法?Golang Worker.Shutdown怎麽用?Golang Worker.Shutdown使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/facette/facette/pkg/worker.Worker
的用法示例。
在下文中一共展示了Worker.Shutdown方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: workerCatalogRun
func workerCatalogRun(w *worker.Worker, args ...interface{}) {
var serverCatalog = w.Props[0].(*catalog.Catalog)
defer w.Shutdown()
logger.Log(logger.LevelDebug, "catalogWorker", "starting")
w.State = worker.JobStarted
for {
select {
case cmd := <-w.ReceiveJobSignals():
switch cmd {
case jobSignalShutdown:
logger.Log(logger.LevelInfo, "catalogWorker", "received shutdown command, stopping job")
w.State = worker.JobStopped
return
default:
logger.Log(logger.LevelNotice, "catalogWorker", "received unknown command, ignoring")
}
case record := <-serverCatalog.RecordChan:
serverCatalog.Insert(record)
}
}
}
示例2: workerProviderRun
func workerProviderRun(w *worker.Worker, args ...interface{}) {
var (
prov = w.Props[0].(*provider.Provider)
timeTicker *time.Ticker
timeChan <-chan time.Time
)
defer func() { w.State = worker.JobStopped }()
defer w.Shutdown()
logger.Log(logger.LevelDebug, "provider", "%s: starting", prov.Name)
// If provider `refresh_interval` has been configured, set up a time ticker
if prov.Config.RefreshInterval > 0 {
timeTicker = time.NewTicker(time.Duration(prov.Config.RefreshInterval) * time.Second)
timeChan = timeTicker.C
}
for {
select {
case _ = <-timeChan:
logger.Log(logger.LevelDebug, "provider", "%s: performing refresh from connector", prov.Name)
if err := prov.Connector.Refresh(prov.Name, prov.Filters.Input); err != nil {
logger.Log(logger.LevelError, "provider", "%s: unable to refresh: %s", prov.Name, err)
continue
}
prov.LastRefresh = time.Now()
case cmd := <-w.ReceiveJobSignals():
switch cmd {
case jobSignalRefresh:
logger.Log(logger.LevelInfo, "provider", "%s: received refresh command", prov.Name)
if err := prov.Connector.Refresh(prov.Name, prov.Filters.Input); err != nil {
logger.Log(logger.LevelError, "provider", "%s: unable to refresh: %s", prov.Name, err)
continue
}
prov.LastRefresh = time.Now()
case jobSignalShutdown:
logger.Log(logger.LevelInfo, "provider", "%s: received shutdown command, stopping job", prov.Name)
w.State = worker.JobStopped
if timeTicker != nil {
// Stop refresh time ticker
timeTicker.Stop()
}
return
default:
logger.Log(logger.LevelNotice, "provider", "%s: received unknown command, ignoring", prov.Name)
}
}
}
}
示例3: workerServeRun
func workerServeRun(w *worker.Worker, args ...interface{}) {
var server = w.Props[0].(*Server)
defer w.Shutdown()
logger.Log(logger.LevelDebug, "serveWorker", "starting")
// Prepare router
router := NewRouter(server)
router.HandleFunc(urlStaticPath, server.serveStatic)
router.HandleFunc(urlCatalogPath, server.serveCatalog)
router.HandleFunc(urlLibraryPath, server.serveLibrary)
router.HandleFunc(urlAdminPath, server.serveAdmin)
router.HandleFunc(urlBrowsePath, server.serveBrowse)
router.HandleFunc(urlShowPath, server.serveShow)
router.HandleFunc(urlReloadPath, server.serveReload)
router.HandleFunc(urlStatsPath, server.serveStats)
router.HandleFunc("/", server.serveBrowse)
http.Handle("/", router)
// Start serving HTTP requests
listener, err := net.Listen("tcp", server.Config.BindAddr)
if err != nil {
w.ReturnErr(err)
return
}
logger.Log(logger.LevelInfo, "serveWorker", "listening on %s", server.Config.BindAddr)
go http.Serve(listener, nil)
for {
select {
case cmd := <-w.ReceiveJobSignals():
switch cmd {
case jobSignalShutdown:
logger.Log(logger.LevelInfo, "serveWorker", "received shutdown command, stopping job")
listener.Close()
logger.Log(logger.LevelInfo, "serveWorker", "server listener closed")
w.State = worker.JobStopped
return
default:
logger.Log(logger.LevelInfo, "serveWorker", "received unknown command, ignoring")
}
}
}
w.ReturnErr(nil)
}
示例4: workerServeRun
func workerServeRun(w *worker.Worker, args ...interface{}) {
var server = w.Props[0].(*Server)
defer w.Shutdown()
logger.Log(logger.LevelDebug, "serveWorker", "starting")
// Prepare router
router := NewRouter(server)
router.HandleFunc(urlStaticPath, server.serveStatic)
router.HandleFunc(urlCatalogPath, server.serveCatalog)
router.HandleFunc(urlLibraryPath, server.serveLibrary)
router.HandleFunc(urlPlotsPath, server.servePlots)
router.HandleFunc(urlAdminPath, server.serveAdmin)
router.HandleFunc(urlBrowsePath, server.serveBrowse)
router.HandleFunc(urlShowPath, server.serveShow)
router.HandleFunc(urlStatsPath, server.serveStats)
router.HandleFunc("/", server.serveBrowse)
http.Handle("/", router)
// Start serving HTTP requests
netType := "tcp"
address := server.Config.BindAddr
for _, scheme := range [...]string{"tcp", "tcp4", "tcp6", "unix"} {
prefix := scheme + "://"
if strings.HasPrefix(address, prefix) {
netType = scheme
address = strings.TrimPrefix(address, prefix)
break
}
}
listener, err := net.Listen(netType, address)
if err != nil {
w.ReturnErr(err)
return
}
logger.Log(logger.LevelInfo, "serveWorker", "listening on %s", server.Config.BindAddr)
if netType == "unix" {
// Change owning user and group
if server.Config.SocketUser >= 0 || server.Config.SocketGroup >= 0 {
logger.Log(logger.LevelDebug, "serveWorker", "changing ownership of unix socket to UID %v and GID %v",
server.Config.SocketUser, server.Config.SocketGroup)
err = os.Chown(address, server.Config.SocketUser, server.Config.SocketGroup)
if err != nil {
listener.Close()
w.ReturnErr(err)
return
}
}
// Change mode
if server.Config.SocketMode != nil {
mode, err := strconv.ParseUint(*server.Config.SocketMode, 8, 32)
if err != nil {
logger.Log(logger.LevelError, "serveWorker", "socket_mode is invalid")
listener.Close()
w.ReturnErr(err)
return
}
logger.Log(logger.LevelDebug, "serveWorker", "changing file permissions mode of unix socket to %04o", mode)
err = os.Chmod(address, os.FileMode(mode))
if err != nil {
listener.Close()
w.ReturnErr(err)
return
}
}
}
go http.Serve(listener, nil)
for {
select {
case cmd := <-w.ReceiveJobSignals():
switch cmd {
case jobSignalShutdown:
logger.Log(logger.LevelInfo, "serveWorker", "received shutdown command, stopping job")
listener.Close()
logger.Log(logger.LevelInfo, "serveWorker", "server listener closed")
w.State = worker.JobStopped
return
default:
logger.Log(logger.LevelInfo, "serveWorker", "received unknown command, ignoring")
}
}
}
//.........這裏部分代碼省略.........