// Schedule instantiates a new OpsGenieScheduleClient.
775741
func (cli *OpsGenieClient) Schedule() (*OpsGenieScheduleClient, error) {
	cli.makeHTTPTransportSettings()

	scheduleClient := new(OpsGenieScheduleClient)
	scheduleClient.SetOpsGenieClient(*cli)

	if cli.opsGenieAPIURL == "" {
		scheduleClient.SetOpsGenieAPIUrl(endpointURL)
	}

	return scheduleClient, nil
}
452167
func (t *TimeoutWheel) Schedule(
	d time.Duration,
	expireCb func(interface{}),
	arg interface{},
) (Timeout, error) {
	dTicks := (d + t.tickInterval - 1) / t.tickInterval
	deadline := atomic.LoadUint64(&t.ticks) + uint64(dTicks)
	timeout := t.getTimeoutLocked(deadline)

	if t.state != running {
		t.putTimeoutLocked(timeout)
		timeout.mtx.Unlock()
		return Timeout{}, ErrSystemStopped
	}

	bucket := &t.buckets[deadline&t.bucketMask]
	timeout.expireCb = expireCb
	timeout.expireArg = arg
	timeout.deadline = deadline
	timeout.state = timeoutActive
	out := Timeout{timeout: timeout, generation: timeout.generation}

	// execute the callback now, return a Timeout that is already Stopped (generation is bumped)
	if bucket.lastTick >= deadline {
		t.putTimeoutLocked(timeout)
		timeout.mtx.Unlock()
		expireCb(arg)
		return out, nil
	}

	timeout.prependLocked(bucket)
	timeout.mtx.Unlock()
	return out, nil
}
209484
func UpdateMaintenanceSchedule(s maintenance.Schedule) *master.Call {
	return &master.Call{
		Type: master.Call_UPDATE_MAINTENANCE_SCHEDULE,
		UpdateMaintenanceSchedule: &master.Call_UpdateMaintenanceSchedule{
			Schedule: s,
		},
	}
}
513913
func (cli *OpsGenieClient) ScheduleOverrideV2() (*OpsGenieScheduleOverrideV2Client, error) {
	cli.makeHTTPTransportSettings()

	scheduleOverrideClient := new(OpsGenieScheduleOverrideV2Client)
	scheduleOverrideClient.SetOpsGenieClient(*cli)

	if cli.opsGenieAPIURL == "" {
		scheduleOverrideClient.SetOpsGenieAPIUrl(endpointURL)
	}

	return scheduleOverrideClient, nil
}
1079185
func (m *MockBuildsServer) ScheduleBuild(arg0 context.Context, arg1 *ScheduleBuildRequest) (*Build, error) {
	m.ctrl.T.Helper()
	ret := m.ctrl.Call(m, "ScheduleBuild", arg0, arg1)
	ret0, _ := ret[0].(*Build)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
1045403
func (w *Worker) Schedule(schedules ...Schedule) (scheduleIds []string, err error) {
	outSchedules := make([]map[string]interface{}, 0, len(schedules))

	for _, schedule := range schedules {
		sm := map[string]interface{}{
			"code_name": schedule.CodeName,
			"name":      schedule.Name,
			"payload":   schedule.Payload,
			"label":     schedule.Label,
			"cluster":   schedule.Cluster,
		}
		if schedule.Delay != nil {
			sm["delay"] = (*schedule.Delay).Seconds()
		}
		if schedule.EndAt != nil {
			sm["end_at"] = *schedule.EndAt
		}
		if schedule.MaxConcurrency != nil {
			sm["max_concurrency"] = *schedule.MaxConcurrency
		}
		if schedule.Priority != nil {
			sm["priority"] = *schedule.Priority
		}
		if schedule.RunEvery != nil {
			sm["run_every"] = *schedule.RunEvery
		}
		if schedule.RunTimes != nil {
			sm["run_times"] = *schedule.RunTimes
		}
		if schedule.StartAt != nil {
			sm["start_at"] = *schedule.StartAt
		}
		outSchedules = append(outSchedules, sm)
	}

	in := map[string][]map[string]interface{}{"schedules": outSchedules}
	out := struct {
		Schedules []struct {
			Id string `json:"id"`
		} `json:"schedules"`
		Msg string `json:"msg"`
	}{}

	err = w.schedules().Req("POST", &in, &out)
	if err != nil {
		return
	}

	scheduleIds = make([]string, 0, len(out.Schedules))

	for _, schedule := range out.Schedules {
		scheduleIds = append(scheduleIds, schedule.Id)
	}

	return
}
548339
func (op *Operator) SchedulerGetConfiguration(q *QueryOptions) (*SchedulerConfigurationResponse, *QueryMeta, error) {
	var resp SchedulerConfigurationResponse
	qm, err := op.c.query("/v1/operator/scheduler/configuration", &resp, q)
	if err != nil {
		return nil, nil, err
	}
	return &resp, qm, nil
}
788032
func (c *Cron) Schedule(schedule Schedule, cmd Job) {
	entry := &Entry{
		Schedule: schedule,
		Job:      cmd,
	}
	if !c.running {
		c.entries = append(c.entries, entry)
		return
	}

	c.add <- entry
}
629381
func (op *Operator) SchedulerSetConfiguration(args *structs.SchedulerSetConfigRequest, reply *structs.SchedulerSetConfigurationResponse) error {
	if done, err := op.srv.forward("Operator.SchedulerSetConfiguration", args, args, reply); done {
		return err
	}

	// This action requires operator write access.
	rule, err := op.srv.ResolveToken(args.AuthToken)
	if err != nil {
		return err
	} else if rule != nil && !rule.AllowOperatorWrite() {
		return structs.ErrPermissionDenied
	}

	// All servers should be at or above 0.9.0 to apply this operatation
	if !ServersMeetMinimumVersion(op.srv.Members(), minSchedulerConfigVersion, false) {
		return fmt.Errorf("All servers should be running version %v to update scheduler config", minSchedulerConfigVersion)
	}
	// Apply the update
	resp, index, err := op.srv.raftApply(structs.SchedulerConfigRequestType, args)
	if err != nil {
		op.logger.Error("failed applying Scheduler configuration", "error", err)
		return err
	} else if respErr, ok := resp.(error); ok {
		return respErr
	}

	// Check if the return type is a bool
	// Only applies to CAS requests
	if respBool, ok := resp.(bool); ok {
		reply.Updated = respBool
	}
	reply.Index = index
	return nil
}
497112
func (s *BatchServiceStateManager) ScheduleServices(svcs []*service.Service, tenantID string, desiredState service.DesiredState, emergency bool) error {
	logger := plog.WithFields(logrus.Fields{
		"servicecount": len(svcs),
		"tenantid":     tenantID,
		"desiredstate": desiredState.String(),
		"emergency":    emergency,
	})

	var err error
	logger.Debug("Scheduling services")
	s.lock.Lock()
	var queues map[service.DesiredState]*ServiceStateQueue
	queues, ok := s.TenantQueues[tenantID]

	if !ok {
		s.lock.Unlock()
		return ErrBadTenantID
	}

	// Get a lock on all queues
	for _, q := range queues {
		q.lock.Lock()
		defer q.lock.Unlock()
	}
	s.lock.Unlock()
	// Build the cancellable services from the list
	cancellableServices := make(map[string]*CancellableService)
	for _, svc := range svcs {
		cancellableServices[svc.ID] = NewCancellableService(svc)
	}

	// Merge with oldBatch batchQueue
	// 1. If this is emergency, merge with other emergencies and move to front of the queue
	// 2. If any service in this batch is currently in the "pending" batch:
	//    A. If the desired states are the same, leave it pending and remove it from this batch
	//    B. If the desired states are different, cancel waits on the pending request and leave it in this batch
	// 3. If this and the last N batches at the end of the queue all have the same desired state, merge and re-group them
	// 4. If any service in this batch also appears in an earlier batch:
	//    A. If the desired state is the same, leave it in the earlier batch and remove it here
	//    B. If the desired state is different, delete it from the earlier batch and leave it in the new one
	newBatch := ServiceStateChangeBatch{
		Services:     cancellableServices,
		DesiredState: desiredState,
		Emergency:    emergency,
	}
	var expeditedBatch ServiceStateChangeBatch
	expeditedServices := make(map[string]*CancellableService)
	var cancelledIDs []string
	for _, queue := range queues {
		// reconcile the new batch against all batches in q
		var cancelled []string
		newBatch, expeditedBatch, cancelled = queue.reconcileWithBatchQueue(newBatch)
		cancelledIDs = append(cancelledIDs, cancelled...)
		for id, svc := range expeditedBatch.Services {
			expeditedServices[id] = svc
		}

		if len(newBatch.Services) == 0 {
			// Nothing left to reconcile
			break
		}

		// reconcile with the pending batch
		newBatch = queue.reconcileWithPendingBatch(newBatch)
	}

	// Now check for services that are already in the desired state
	var cancelled []string
	newBatch, cancelled = s.reconcileWithCurrentState(newBatch)
	cancelledIDs = append(cancelledIDs, cancelled...)

	if len(cancelledIDs) > 0 {
		// Spawn a goroutine to update the current state of all cancelled services
		defer func() {
			logger.WithField("services", cancelledIDs).Debug("Cancelling and re-syncing services")
			go s.SyncCurrentStates(cancelledIDs)
		}()
	}

	expeditedBatch.Services = expeditedServices

	if len(expeditedBatch.Services) > 0 {
		// process the expedited batch now
		go func() {
			s.updateBatch(&expeditedBatch)
			failed := s.processBatch(tenantID, expeditedBatch)
			// Cancel these services to notify waiters that they have been scheduled
			for _, svc := range expeditedBatch.Services {
				svc.Cancel()
			}
			if len(failed) > 0 {
				s.SyncCurrentStates(failed)
			}
		}()
	}

	if len(newBatch.Services) == 0 {
		return nil
	}

	queueDesiredState := newBatch.DesiredState
	switch newBatch.DesiredState {
	case service.SVCRestart:
		queueDesiredState = service.SVCRun
	case service.SVCPause:
		queueDesiredState = service.SVCStop
	}

	// Merge this into the queue
	queue, ok := queues[queueDesiredState]
	if !ok {
		return ErrMissingQueue
	}

	if newBatch.Emergency {
		err = queue.mergeEmergencyBatch(newBatch)
	} else {
		err = queue.mergeBatch(newBatch)
	}

	// Set pending desired state
	currentState := service.DesiredToCurrentPendingState(newBatch.DesiredState, newBatch.Emergency)
	var sids []string
	for sid := range newBatch.Services {
		sids = append(sids, sid)
	}
	s.currentStateLock.Lock()
	s.updateServiceCurrentState(currentState, sids...)
	s.currentStateLock.Unlock()

	// Signal update or exit
	select {
	case queue.Changed <- true:
	default:
	}

	return err
}
902773
func (s *Trigger) SetSchedule(v string) *Trigger {
	s.Schedule = &v
	return s
}
1130584
func NewServiceScheduler(logger log.Logger, state State, planner Planner) Scheduler {
	s := &GenericScheduler{
		logger:  logger.Named("service_sched"),
		state:   state,
		planner: planner,
		batch:   false,
	}
	return s
}
181168
func Schedule(d time.Duration, fn func(), r Recovery) Canceler {
	s := &scheduler{
		d:     d,
		fn:    fn,
		r:     r,
		state: 1,
	}
	s.timer = time.AfterFunc(d, s.schedule)
	return s
}
823618
func NewBatchScheduler(logger log.Logger, state State, planner Planner) Scheduler {
	s := &GenericScheduler{
		logger:  logger.Named("batch_sched"),
		state:   state,
		planner: planner,
		batch:   true,
	}
	return s
}
220752
func parseCronSchedule(expr string, randSeed uint64) (*Schedule, error) {
	cronexprLock.Lock()
	exp, err := cronexpr.Parse(expr)
	cronexprLock.Unlock()
	if err != nil {
		return nil, err
	}
	return &Schedule{cronExpr: exp}, nil
}
864133
func (mr *MockBuildsServerMockRecorder) ScheduleBuild(arg0, arg1 interface{}) *gomock.Call {
	mr.mock.ctrl.T.Helper()
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ScheduleBuild", reflect.TypeOf((*MockBuildsServer)(nil).ScheduleBuild), arg0, arg1)
}
353078
func (p *AuroraSchedulerManagerClient) ScheduleCronJob(ctx context.Context, description *JobConfiguration) (r *Response, err error) {
  var _args133 AuroraSchedulerManagerScheduleCronJobArgs
  _args133.Description = description
  var _result134 AuroraSchedulerManagerScheduleCronJobResult
  if err = p.Client_().Call(ctx, "scheduleCronJob", &_args133, &_result134); err != nil {
    return
  }
  return _result134.GetSuccess(), nil
}