// parseWithSchedule parses "with <interval> interval" schedule string.
978068
func parseWithSchedule(expr string, randSeed uint64) (*Schedule, error) {
	tokens := strings.SplitN(expr, " ", 3)
	if len(tokens) != 3 || tokens[0] != "with" || tokens[2] != "interval" {
		return nil, errors.New("expecting format \"with <duration> interval\"")
	}
	interval, err := time.ParseDuration(tokens[1])
	if err != nil {
		return nil, fmt.Errorf("bad duration %q - %s", tokens[1], err)
	}
	if interval < 0 {
		return nil, fmt.Errorf("bad interval %q - it must be positive", tokens[1])
	}
	return &Schedule{interval: interval}, nil
}
1091169
func parseDaily(dailyStr string) (RetainIntervalSpec, error) {
	r, daily, err := parseRetainNumber(dailyStr)
	if err != nil {
		return r, err
	}
	if daily == "" {
		return r, fmt.Errorf("Daily schedule is missing")
	}
	dt := strings.Split(daily, "@")
	h, m, err := timeOfDay(dt[len(dt)-1])
	if err != nil {
		return RetainIntervalSpec{}, err
	}
	r.IntervalSpec = Daily(h, m).Spec()
	return r, nil
}
605675
func (r *Run) ScheduledForTime() (time.Time, error) {
	return time.Parse(time.RFC3339, r.ScheduledFor)
}
968329
func (s *ScheduledAction) SetSchedule(v string) *ScheduledAction {
	s.Schedule = &v
	return s
}
437715
func Wait4Scheduled(count int, timeout time.Duration) bool {
	return provider.Wait4Scheduled(count, timeout)
}
879609
func (e *Job) ParseSchedule() (*schedule.Schedule, error) {
	if e.cachedSchedule == nil && e.cachedScheduleErr == nil {
		hash := fnv.New64()
		hash.Write([]byte(e.JobID))
		seed := hash.Sum64()
		e.cachedSchedule, e.cachedScheduleErr = schedule.Parse(e.EffectiveSchedule(), seed)
		if e.cachedSchedule == nil && e.cachedScheduleErr == nil {
			panic("no schedule and no error")
		}
	}
	return e.cachedSchedule, e.cachedScheduleErr
}
651020
func parseHour(buff []byte, cursor *int, l int) (int, error) {
	return syslogparser.Parse2Digits(buff, cursor, l, 0, 23, ErrHourInvalid)
}
399979
func (s *CreateCrawlerInput) SetSchedule(v string) *CreateCrawlerInput {
	s.Schedule = &v
	return s
}
1050058
func (d *DB) maybeScheduleCompaction() {
	if d.compacting || d.closed {
		return
	}
	// TODO: check for manual compactions.
	if d.imm == nil {
		v := d.versions.currentVersion()
		// TODO: check v.fileToCompact.
		if v.compactionScore < 1 {
			// There is no work to be done.
			return
		}
	}
	d.compacting = true
	go d.compact()
}
951217
func (bridge *Bridge) CreateSchedule(schedule Schedule) error {
	uri := fmt.Sprintf("/api/%s/schedules", bridge.Username)
	body, _, err := bridge.Post(uri, schedule)
	if err != nil {
		return err
	}

	fmt.Println("CREATE SCHEDULE BODY: ", string(body))
	return nil
}
118335
func Scheduler(c context.Context, cfg *pb.ProjectConfig) error {
	// Sort jobs by ID.
	sort.Slice(cfg.Job, func(i, j int) bool {
		return cfg.Job[i].Id < cfg.Job[j].Id
	})
	sort.Slice(cfg.Trigger, func(i, j int) bool {
		return cfg.Trigger[i].Id < cfg.Trigger[j].Id
	})

	// ACL set name => list of ACLs.
	aclSets := make(map[string][]*pb.Acl)
	for _, s := range cfg.AclSets {
		aclSets[s.Name] = s.Acls
	}

	// Expand ACL sets.
	for _, x := range cfg.Job {
		x.Acls = normalizeACLs(x.Acls, x.AclSets, aclSets)
		x.AclSets = nil
	}
	for _, x := range cfg.Trigger {
		x.Acls = normalizeACLs(x.Acls, x.AclSets, aclSets)
		x.AclSets = nil
	}
	cfg.AclSets = nil

	// Normalize triggers.
	for _, x := range cfg.Trigger {
		sort.Strings(x.Triggers)
		if gt := x.Gitiles; gt != nil {
			for i, r := range gt.Refs {
				if !strings.HasPrefix(r, "regexp:") {
					gt.Refs[i] = "regexp:" + regexp.QuoteMeta(r)
				}
			}
			sort.Strings(gt.Refs)
		}
	}

	return nil
}
1027390
func (s *PutRuleInput) SetScheduleExpression(v string) *PutRuleInput {
	s.ScheduleExpression = &v
	return s
}
798098
func (s *GetMaintenanceWindowOutput) SetSchedule(v string) *GetMaintenanceWindowOutput {
	s.Schedule = &v
	return s
}
1211738
func (s *Rule) SetScheduleExpression(v string) *Rule {
	s.ScheduleExpression = &v
	return s
}
131614
func ScheduleUnmarshalJSON(b []byte) (schedule Schedule, err error) {
	var mixed interface{}
	json.Unmarshal(b, &mixed)

	for key, value := range mixed.(map[string]interface{}) {
		rawValue, _ := json.Marshal(value)
		switch key {
		case "date":
			var date Date
			err = json.Unmarshal(rawValue, &date)
			schedule = date
		case "day":
			var day Day
			err = json.Unmarshal(rawValue, &day)
			schedule = day
		case "intersection":
			var intersection Intersection
			err = json.Unmarshal(rawValue, &intersection)
			schedule = intersection
		case "month":
			var month Month
			err = json.Unmarshal(rawValue, &month)
			schedule = month
		case "union":
			var union Union
			err = json.Unmarshal(rawValue, &union)
			schedule = union
		case "week":
			var week Week
			err = json.Unmarshal(rawValue, &week)
			schedule = week
		case "weekday":
			var weekday Weekday
			err = json.Unmarshal(rawValue, &weekday)
			schedule = weekday
		case "year":
			var year Year
			err = json.Unmarshal(rawValue, &year)
			schedule = year
		default:
			err = fmt.Errorf("%s is not a recognized schedule", key)
		}
	}
	return
}
972157
func (g *genericScheduler) Schedule(pod *v1.Pod, nodeLister algorithm.NodeLister) (result ScheduleResult, err error) {
	trace := utiltrace.New(fmt.Sprintf("Scheduling %s/%s", pod.Namespace, pod.Name))
	defer trace.LogIfLong(100 * time.Millisecond)

	if err := podPassesBasicChecks(pod, g.pvcLister); err != nil {
		return result, err
	}

	nodes, err := nodeLister.List()
	if err != nil {
		return result, err
	}
	if len(nodes) == 0 {
		return result, ErrNoNodesAvailable
	}

	if err := g.snapshot(); err != nil {
		return result, err
	}

	trace.Step("Computing predicates")
	startPredicateEvalTime := time.Now()
	filteredNodes, failedPredicateMap, err := g.findNodesThatFit(pod, nodes)
	if err != nil {
		return result, err
	}

	if len(filteredNodes) == 0 {
		return result, &FitError{
			Pod:              pod,
			NumAllNodes:      len(nodes),
			FailedPredicates: failedPredicateMap,
		}
	}
	metrics.SchedulingAlgorithmPredicateEvaluationDuration.Observe(metrics.SinceInSeconds(startPredicateEvalTime))
	metrics.DeprecatedSchedulingAlgorithmPredicateEvaluationDuration.Observe(metrics.SinceInMicroseconds(startPredicateEvalTime))
	metrics.SchedulingLatency.WithLabelValues(metrics.PredicateEvaluation).Observe(metrics.SinceInSeconds(startPredicateEvalTime))
	metrics.DeprecatedSchedulingLatency.WithLabelValues(metrics.PredicateEvaluation).Observe(metrics.SinceInSeconds(startPredicateEvalTime))

	trace.Step("Prioritizing")
	startPriorityEvalTime := time.Now()
	// When only one node after predicate, just use it.
	if len(filteredNodes) == 1 {
		metrics.SchedulingAlgorithmPriorityEvaluationDuration.Observe(metrics.SinceInSeconds(startPriorityEvalTime))
		metrics.DeprecatedSchedulingAlgorithmPriorityEvaluationDuration.Observe(metrics.SinceInMicroseconds(startPriorityEvalTime))
		return ScheduleResult{
			SuggestedHost:  filteredNodes[0].Name,
			EvaluatedNodes: 1 + len(failedPredicateMap),
			FeasibleNodes:  1,
		}, nil
	}

	metaPrioritiesInterface := g.priorityMetaProducer(pod, g.nodeInfoSnapshot.NodeInfoMap)
	priorityList, err := PrioritizeNodes(pod, g.nodeInfoSnapshot.NodeInfoMap, metaPrioritiesInterface, g.prioritizers, filteredNodes, g.extenders)
	if err != nil {
		return result, err
	}
	metrics.SchedulingAlgorithmPriorityEvaluationDuration.Observe(metrics.SinceInSeconds(startPriorityEvalTime))
	metrics.DeprecatedSchedulingAlgorithmPriorityEvaluationDuration.Observe(metrics.SinceInMicroseconds(startPriorityEvalTime))
	metrics.SchedulingLatency.WithLabelValues(metrics.PriorityEvaluation).Observe(metrics.SinceInSeconds(startPriorityEvalTime))
	metrics.DeprecatedSchedulingLatency.WithLabelValues(metrics.PriorityEvaluation).Observe(metrics.SinceInSeconds(startPriorityEvalTime))

	trace.Step("Selecting host")

	host, err := g.selectHost(priorityList)
	return ScheduleResult{
		SuggestedHost:  host,
		EvaluatedNodes: len(filteredNodes) + len(failedPredicateMap),
		FeasibleNodes:  len(filteredNodes),
	}, err
}
502612
func (as atSchedule) Next(t time.Time) time.Time {
	next := as.reset(t)
	if t.After(next) {
		return next.Add(as.period)
	}
	return next
}