本文整理匯總了Golang中github.com/pivotal-golang/clock.NewClock函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewClock函數的具體用法?Golang NewClock怎麽用?Golang NewClock使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewClock函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: WaitForVirtualGuestToHaveNoRunningTransaction
func WaitForVirtualGuestToHaveNoRunningTransaction(softLayerClient sl.Client, virtualGuestId int, logger boshlog.Logger) error {
virtualGuestService, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client")
}
runningTransactionsRetryable := boshretry.NewRetryable(
func() (bool, error) {
activeTransactions, err := virtualGuestService.GetActiveTransactions(virtualGuestId)
if err != nil {
return false, bosherr.WrapErrorf(err, "Getting active transaction against vitrual guest %d", virtualGuestId)
} else {
if len(activeTransactions) == 0 {
return false, nil
}
return true, nil
}
})
timeService := clock.NewClock()
timeoutRetryStrategy := boshretry.NewTimeoutRetryStrategy(TIMEOUT, POLLING_INTERVAL, runningTransactionsRetryable, timeService, logger)
err = timeoutRetryStrategy.Try()
if err != nil {
return bosherr.Errorf("Waiting for virtual guest with ID '%d' to have no active transactions", virtualGuestId)
}
return nil
}
示例2: WaitForVirtualGuestIsNotPingable
func WaitForVirtualGuestIsNotPingable(softLayerClient sl.Client, virtualGuestId int, logger boshlog.Logger) error {
virtualGuestService, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client")
}
checkPingableRetryable := boshretry.NewRetryable(
func() (bool, error) {
state, err := virtualGuestService.IsPingable(virtualGuestId)
if err != nil {
return false, bosherr.WrapErrorf(err, "Checking pingable against vitrual guest %d", virtualGuestId)
} else {
return state, nil
}
})
timeService := clock.NewClock()
timeoutRetryStrategy := boshretry.NewTimeoutRetryStrategy(TIMEOUT, POLLING_INTERVAL, checkPingableRetryable, timeService, logger)
err = timeoutRetryStrategy.Try()
if err != nil {
return bosherr.Errorf("Waiting for virtual guest with ID '%d' is not pingable", virtualGuestId)
}
return nil
}
示例3: main
func main() {
logger := newLogger()
defer logger.HandlePanic("Main")
fileSystem := boshsys.NewOsFileSystemWithStrictTempRoot(logger)
workspaceRootPath := path.Join(os.Getenv("HOME"), ".bosh_init")
ui := biui.NewConsoleUI(logger)
timeService := clock.NewClock()
cmdFactory := bicmd.NewFactory(
fileSystem,
ui,
timeService,
logger,
boshuuid.NewGenerator(),
workspaceRootPath,
)
cmdRunner := bicmd.NewRunner(cmdFactory)
stage := biui.NewStage(ui, timeService, logger)
err := cmdRunner.Run(stage, os.Args[1:]...)
if err != nil {
displayHelpFunc := func() {
if strings.Contains(err.Error(), "Invalid usage") {
ui.ErrorLinef("")
helpErr := cmdRunner.Run(stage, append([]string{"help"}, os.Args[1:]...)...)
if helpErr != nil {
logger.Error(mainLogTag, "Couldn't print help: %s", helpErr.Error())
}
}
}
fail(err, ui, logger, displayHelpFunc)
}
}
示例4: Workers
func (provider *dbProvider) Workers() ([]Worker, error) {
workerInfos, err := provider.db.Workers()
if err != nil {
return nil, err
}
tikTok := clock.NewClock()
workers := make([]Worker, len(workerInfos))
for i, info := range workerInfos {
workerLog := provider.logger.Session("worker-connection", lager.Data{
"addr": info.Addr,
})
gardenConn := RetryableConnection{
Logger: workerLog,
Connection: gconn.NewWithLogger("tcp", info.Addr, workerLog.Session("garden-connection")),
Sleeper: tikTok,
RetryPolicy: ExponentialRetryPolicy{
Timeout: 5 * time.Minute,
},
}
workers[i] = NewGardenWorker(
gclient.New(gardenConn),
tikTok,
info.ActiveContainers,
info.ResourceTypes,
info.Platform,
info.Tags,
)
}
return workers, nil
}
示例5: NewProvider
func NewProvider(
platform boshplatform.Platform,
client boshmonit.Client,
logger boshlog.Logger,
dirProvider boshdir.Provider,
handler boshhandler.Handler,
) (p Provider) {
fs := platform.GetFs()
runner := platform.GetRunner()
timeService := clock.NewClock()
monitJobSupervisor := NewMonitJobSupervisor(
fs,
runner,
client,
logger,
dirProvider,
jobSupervisorListenPort,
MonitReloadOptions{
MaxTries: 3,
MaxCheckTries: 6,
DelayBetweenCheckTries: 5 * time.Second,
},
timeService,
)
p.supervisors = map[string]JobSupervisor{
"monit": monitJobSupervisor,
"dummy": NewDummyJobSupervisor(),
"dummy-nats": NewDummyNatsJobSupervisor(handler),
"windows": NewWindowsJobSupervisor(runner, dirProvider, fs, logger, jobSupervisorListenPort, make(chan bool)),
}
return
}
示例6: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
flag.Parse()
cf_http.Initialize(*communicationTimeout)
logger, reconfigurableSink := cf_lager.New("auctioneer")
initializeDropsonde(logger)
if err := validateBBSAddress(); err != nil {
logger.Fatal("invalid-bbs-address", err)
}
consulClient, err := consuladapter.NewClientFromUrl(*consulCluster)
if err != nil {
logger.Fatal("new-client-failed", err)
}
port, err := strconv.Atoi(strings.Split(*listenAddr, ":")[1])
if err != nil {
logger.Fatal("invalid-port", err)
}
clock := clock.NewClock()
auctioneerServiceClient := auctioneer.NewServiceClient(consulClient, clock)
auctionRunner := initializeAuctionRunner(logger, *cellStateTimeout,
initializeBBSClient(logger), *startingContainerWeight)
auctionServer := initializeAuctionServer(logger, auctionRunner)
lockMaintainer := initializeLockMaintainer(logger, auctioneerServiceClient, port)
registrationRunner := initializeRegistrationRunner(logger, consulClient, clock, port)
members := grouper.Members{
{"lock-maintainer", lockMaintainer},
{"auction-runner", auctionRunner},
{"auction-server", auctionServer},
{"registration-runner", registrationRunner},
}
if dbgAddr := cf_debug_server.DebugAddress(flag.CommandLine); dbgAddr != "" {
members = append(grouper.Members{
{"debug-server", cf_debug_server.Runner(dbgAddr, reconfigurableSink)},
}, members...)
}
group := grouper.NewOrdered(os.Interrupt, members)
monitor := ifrit.Invoke(sigmon.New(group))
logger.Info("started")
err = <-monitor.Wait()
if err != nil {
logger.Error("exited-with-failure", err)
os.Exit(1)
}
logger.Info("exited")
}
示例7: initializeReceptorBBS
func initializeReceptorBBS(etcdOptions *etcdstoreadapter.ETCDOptions, logger lager.Logger) Bbs.ReceptorBBS {
workPool, err := workpool.NewWorkPool(100)
if err != nil {
logger.Fatal("failed-to-construct-etcd-adapter-workpool", err, lager.Data{"num-workers": 100}) // should never happen
}
etcdAdapter, err := etcdstoreadapter.New(etcdOptions, workPool)
if err != nil {
logger.Fatal("failed-to-construct-etcd-tls-client", err)
}
client, err := consuladapter.NewClient(*consulCluster)
if err != nil {
logger.Fatal("new-client-failed", err)
}
sessionMgr := consuladapter.NewSessionManager(client)
consulSession, err := consuladapter.NewSession("receptor", *lockTTL, client, sessionMgr)
if err != nil {
logger.Fatal("consul-session-failed", err)
}
return Bbs.NewReceptorBBS(etcdAdapter, consulSession, *taskHandlerAddress, clock.NewClock(), logger)
}
示例8: WaitForVirtualGuestToTargetState
func WaitForVirtualGuestToTargetState(softLayerClient sl.Client, virtualGuestId int, targetState string, logger boshlog.Logger) error {
virtualGuestService, err := softLayerClient.GetSoftLayer_Virtual_Guest_Service()
if err != nil {
return bosherr.WrapError(err, "Creating VirtualGuestService from SoftLayer client")
}
getTargetStateRetryable := boshretry.NewRetryable(
func() (bool, error) {
vgPowerState, err := virtualGuestService.GetPowerState(virtualGuestId)
if err != nil {
return false, bosherr.WrapErrorf(err, "Getting PowerState from vitrual guest %d", virtualGuestId)
} else {
if strings.Contains(vgPowerState.KeyName, targetState) {
return false, nil
}
return true, nil
}
})
timeService := clock.NewClock()
timeoutRetryStrategy := boshretry.NewTimeoutRetryStrategy(TIMEOUT, POLLING_INTERVAL, getTargetStateRetryable, timeService, logger)
err = timeoutRetryStrategy.Try()
if err != nil {
return bosherr.Errorf("Waiting for virtual guest with ID '%d' to have be in state '%s'", virtualGuestId, targetState)
}
return nil
}
示例9: appendStaticWorker
func (cmd *ATCCommand) appendStaticWorker(
logger lager.Logger,
sqlDB *db.SQLDB,
members []grouper.Member,
) []grouper.Member {
if cmd.Worker.GardenURL.URL() == nil {
return members
}
var resourceTypes []atc.WorkerResourceType
for t, resourcePath := range cmd.Worker.ResourceTypes {
resourceTypes = append(resourceTypes, atc.WorkerResourceType{
Type: t,
Image: resourcePath,
})
}
return append(members,
grouper.Member{
Name: "static-worker",
Runner: worker.NewHardcoded(
logger,
sqlDB,
clock.NewClock(),
cmd.Worker.GardenURL.URL().Host,
cmd.Worker.BaggageclaimURL.String(),
resourceTypes,
),
},
)
}
示例10: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
flag.Parse()
cf_http.Initialize(*communicationTimeout)
logger, reconfigurableSink := cf_lager.New("auctioneer")
initializeDropsonde(logger)
if err := validateBBSAddress(); err != nil {
logger.Fatal("invalid-bbs-address", err)
}
client, err := consuladapter.NewClient(*consulCluster)
if err != nil {
logger.Fatal("new-client-failed", err)
}
sessionMgr := consuladapter.NewSessionManager(client)
consulSession, err := consuladapter.NewSession("auctioneer", *lockTTL, client, sessionMgr)
if err != nil {
logger.Fatal("consul-session-failed", err)
}
clock := clock.NewClock()
bbsServiceClient := bbs.NewServiceClient(consulSession, clock)
auctioneerServiceClient := auctioneer.NewServiceClient(consulSession, clock)
auctionRunner := initializeAuctionRunner(logger, *cellStateTimeout, initializeBBSClient(logger), bbsServiceClient)
auctionServer := initializeAuctionServer(logger, auctionRunner)
lockMaintainer := initializeLockMaintainer(logger, auctioneerServiceClient)
members := grouper.Members{
{"lock-maintainer", lockMaintainer},
{"auction-runner", auctionRunner},
{"auction-server", auctionServer},
}
if dbgAddr := cf_debug_server.DebugAddress(flag.CommandLine); dbgAddr != "" {
members = append(grouper.Members{
{"debug-server", cf_debug_server.Runner(dbgAddr, reconfigurableSink)},
}, members...)
}
group := grouper.NewOrdered(os.Interrupt, members)
monitor := ifrit.Invoke(sigmon.New(group))
logger.Info("started")
err = <-monitor.Wait()
if err != nil {
logger.Error("exited-with-failure", err)
os.Exit(1)
}
logger.Info("exited")
}
示例11: initializeServiceClient
func initializeServiceClient(logger lager.Logger) nsync.ServiceClient {
consulClient, err := consuladapter.NewClientFromUrl(*consulCluster)
if err != nil {
logger.Fatal("new-client-failed", err)
}
return nsync.NewServiceClient(consulClient, clock.NewClock())
}
示例12: QueryVMInfobyAgentID
func (vmInfoDB *VMInfoDB) QueryVMInfobyAgentID(retryTimeout time.Duration, retryInterval time.Duration) error {
execStmtRetryable := boshretry.NewRetryable(
func() (bool, error) {
tx, err := vmInfoDB.db.Begin()
if err != nil {
sqliteErr := err.(sqlite3.Error)
if sqliteErr.Code == sqlite3.ErrBusy || sqliteErr.Code == sqlite3.ErrLocked {
return true, bosherr.WrapError(sqliteErr, "retrying...")
} else {
return false, bosherr.WrapError(sqliteErr, "Failed to begin DB transcation")
}
}
var prepareStmt string
if vmInfoDB.VmProperties.InUse == "t" {
prepareStmt = "SELECT id, image_id, agent_id FROM vms WHERE in_use='t' AND agent_id=?"
} else if vmInfoDB.VmProperties.InUse == "f" {
prepareStmt = "SELECT id, image_id, agent_id FROM vms WHERE in_use='f' AND agent_id=?"
} else {
prepareStmt = "SELECT id, image_id, agent_id FROM vms WHERE agent_id==?"
}
sqlStmt, err := tx.Prepare(prepareStmt)
defer sqlStmt.Close()
if err != nil {
sqliteErr := err.(sqlite3.Error)
if sqliteErr.Code == sqlite3.ErrBusy || sqliteErr.Code == sqlite3.ErrLocked {
return true, bosherr.WrapError(sqliteErr, "retrying...")
} else {
return false, bosherr.WrapError(sqliteErr, "Failed to prepare sql statement")
}
}
err = sqlStmt.QueryRow(vmInfoDB.VmProperties.AgentId).Scan(&vmInfoDB.VmProperties.Id, &vmInfoDB.VmProperties.ImageId, &vmInfoDB.VmProperties.AgentId)
if err != nil && !strings.Contains(err.Error(), "no rows") {
sqliteErr := err.(sqlite3.Error)
if sqliteErr.Code == sqlite3.ErrBusy || sqliteErr.Code == sqlite3.ErrLocked {
return true, bosherr.WrapError(sqliteErr, "retrying...")
} else {
return false, bosherr.WrapError(sqliteErr, "Failed to query VM info from vms table")
}
}
tx.Commit()
return false, nil
})
timeService := clock.NewClock()
timeoutRetryStrategy := boshretry.NewTimeoutRetryStrategy(retryTimeout, retryInterval, execStmtRetryable, timeService, vmInfoDB.logger)
err := timeoutRetryStrategy.Try()
if err != nil {
return bosherr.WrapError(err, fmt.Sprintf("Failed to run QueryVMInfobyAgentID"))
} else {
return nil
}
}
示例13: retryRoundTripper
func retryRoundTripper(logger lager.Logger, rt http.RoundTripper) http.RoundTripper {
return &retryhttp.RetryRoundTripper{
Logger: logger,
Sleeper: clock.NewClock(),
RetryPolicy: retryhttp.ExponentialRetryPolicy{
Timeout: 5 * time.Minute,
},
RoundTripper: rt,
}
}
示例14: NewNode
// NewNode generates a new Raft node
func NewNode(opts NodeOptions) *Node {
cfg := opts.Config
if cfg == nil {
cfg = DefaultNodeConfig()
}
if opts.TickInterval == 0 {
opts.TickInterval = time.Second
}
if opts.SendTimeout == 0 {
opts.SendTimeout = 2 * time.Second
}
raftStore := raft.NewMemoryStorage()
n := &Node{
cluster: membership.NewCluster(2 * cfg.ElectionTick),
raftStore: raftStore,
opts: opts,
Config: &raft.Config{
ElectionTick: cfg.ElectionTick,
HeartbeatTick: cfg.HeartbeatTick,
Storage: raftStore,
MaxSizePerMsg: cfg.MaxSizePerMsg,
MaxInflightMsgs: cfg.MaxInflightMsgs,
Logger: cfg.Logger,
},
doneCh: make(chan struct{}),
removeRaftCh: make(chan struct{}),
stopped: make(chan struct{}),
leadershipBroadcast: watch.NewQueue(),
lastSendToMember: make(map[uint64]chan struct{}),
keyRotator: opts.KeyRotator,
}
n.memoryStore = store.NewMemoryStore(n)
if opts.ClockSource == nil {
n.ticker = clock.NewClock().NewTicker(opts.TickInterval)
} else {
n.ticker = opts.ClockSource.NewTicker(opts.TickInterval)
}
n.reqIDGen = idutil.NewGenerator(uint16(n.Config.ID), time.Now())
n.wait = newWait()
n.removeRaftFunc = func(n *Node) func() {
var removeRaftOnce sync.Once
return func() {
removeRaftOnce.Do(func() {
close(n.removeRaftCh)
})
}
}(n)
return n
}
示例15: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
flag.Parse()
cf_http.Initialize(*communicationTimeout)
logger, reconfigurableSink := cf_lager.New(*sessionName)
natsClient := diegonats.NewClient()
clock := clock.NewClock()
syncer := syncer.NewSyncer(clock, *syncInterval, natsClient, logger)
initializeDropsonde(logger)
natsClientRunner := diegonats.NewClientRunner(*natsAddresses, *natsUsername, *natsPassword, logger, natsClient)
table := initializeRoutingTable()
emitter := initializeNatsEmitter(natsClient, logger)
watcher := ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
return watcher.NewWatcher(initializeBBSClient(logger), clock, table, emitter, syncer.Events(), logger).Run(signals, ready)
})
syncRunner := ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
return syncer.Run(signals, ready)
})
lockMaintainer := initializeLockMaintainer(logger, *consulCluster, *sessionName, *lockTTL, *lockRetryInterval, clock)
members := grouper.Members{
{"lock-maintainer", lockMaintainer},
{"nats-client", natsClientRunner},
{"watcher", watcher},
{"syncer", syncRunner},
}
if dbgAddr := cf_debug_server.DebugAddress(flag.CommandLine); dbgAddr != "" {
members = append(grouper.Members{
{"debug-server", cf_debug_server.Runner(dbgAddr, reconfigurableSink)},
}, members...)
}
group := grouper.NewOrdered(os.Interrupt, members)
monitor := ifrit.Invoke(sigmon.New(group))
logger.Info("started")
err := <-monitor.Wait()
if err != nil {
logger.Error("exited-with-failure", err)
os.Exit(1)
}
logger.Info("exited")
}