本文整理匯總了Golang中github.com/facette/facette/pkg/worker.Worker類的典型用法代碼示例。如果您正苦於以下問題:Golang Worker類的具體用法?Golang Worker怎麽用?Golang Worker使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Worker類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: workerProviderShutdown
func workerProviderShutdown(w *worker.Worker, args ...interface{}) {
var prov = w.Props[0].(*provider.Provider)
logger.Log(logger.LevelDebug, "provider", "%s: shutdown", prov.Name)
w.SendJobSignal(jobSignalShutdown)
}
示例2: workerServeShutdown
func workerServeShutdown(w *worker.Worker, args ...interface{}) {
logger.Log(logger.LevelDebug, "serveWorker", "shutdown")
w.SendJobSignal(jobSignalShutdown)
w.ReturnErr(nil)
}
示例3: workerProviderRefresh
func workerProviderRefresh(w *worker.Worker, args ...interface{}) {
var prov = w.Props[0].(*provider.Provider)
logger.Log(logger.LevelDebug, "provider", "%s: refresh", prov.Name)
w.SendJobSignal(jobSignalRefresh)
}
示例4: workerServeInit
func workerServeInit(w *worker.Worker, args ...interface{}) {
var server = args[0].(*Server)
logger.Log(logger.LevelDebug, "serveWorker", "init")
// Worker properties:
// 0: server instance (*Server)
w.Props = append(w.Props, server)
w.ReturnErr(nil)
}
示例5: workerCatalogInit
func workerCatalogInit(w *worker.Worker, args ...interface{}) {
var catalog = args[0].(*catalog.Catalog)
logger.Log(logger.LevelDebug, "catalogWorker", "init")
// Worker properties:
// 0: catalog instance (*catalog.Catalog)
w.Props = append(w.Props, catalog)
w.ReturnErr(nil)
}
示例6: 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)
}
示例7: 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)
}
}
}
}
示例8: 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)
}
}
}
示例9: workerProviderInit
func workerProviderInit(w *worker.Worker, args ...interface{}) {
var (
prov = args[0].(*provider.Provider)
connectorType = args[1].(string)
)
logger.Log(logger.LevelDebug, "provider", "%s: init", prov.Name)
// Instanciate the connector according to its type
conn, err := connector.Connectors[connectorType](prov.Name, prov.Config.Connector)
if err != nil {
w.ReturnErr(err)
return
}
prov.Connector = conn.(connector.Connector)
// Worker properties:
// 0: provider instance (*provider.Provider)
w.Props = append(w.Props, prov)
w.ReturnErr(nil)
}
示例10: 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")
}
}
}
//.........這裏部分代碼省略.........