當前位置: 首頁>>代碼示例>>Golang>>正文


Golang cron.Parse函數代碼示例

本文整理匯總了Golang中github.com/robfig/cron.Parse函數的典型用法代碼示例。如果您正苦於以下問題:Golang Parse函數的具體用法?Golang Parse怎麽用?Golang Parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Parse函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: nextRun

func nextRun(schedule string) (int64, error) {
	sched, err := cron.Parse(schedule)
	if err != nil {
		return 0, err
	}
	return sched.Next(time.Now().UTC()).UnixNano(), nil
}
開發者ID:johnnoone,項目名稱:hooky,代碼行數:7,代碼來源:task.go

示例2: Add

//create a schdule with the cmd ID (overrides old ones) and
func (sched *Scheduler) Add(cmd *core.Command) (interface{}, error) {
	defer sched.restart()

	db := sched.pool.Get()
	defer db.Close()

	job := &SchedulerJob{}

	err := json.Unmarshal([]byte(cmd.Data), job)

	if err != nil {
		log.Println("Failed to load command spec", cmd.Data, err)
		return nil, err
	}

	_, err = cron.Parse(job.Cron)
	if err != nil {
		return nil, err
	}

	job.ID = cmd.ID
	//we can safely push the command to the hashset now.
	db.Do("HSET", hashScheduleKey, cmd.ID, cmd.Data)

	return true, nil
}
開發者ID:amrhassan,項目名稱:agentcontroller2-scrubbed,代碼行數:27,代碼來源:schedule.go

示例3: ValidCron

// ValidCron checks if the syntax of value is valid for a cron job
func ValidCron(value string) error {
	_, err := cron.Parse(value)
	if err != nil {
		return errors.New(notValidCron)
	}
	return nil
}
開發者ID:slok,項目名稱:khronos,代碼行數:8,代碼來源:validate.go

示例4: Set

func (c *CronValue) Set(value string) error {
	_, err := cron.Parse(value)
	if err != nil {
		return fmt.Errorf("expected cron expression or '@every DURATION' got '%s'", value)
	}
	*c = (CronValue)(value)
	return nil
}
開發者ID:rach,項目名稱:pome,代碼行數:8,代碼來源:main.go

示例5: validateScheduleFormat

func validateScheduleFormat(schedule string, fldPath *field.Path) field.ErrorList {
	allErrs := field.ErrorList{}
	_, err := cron.Parse(schedule)
	if err != nil {
		allErrs = append(allErrs, field.Invalid(fldPath, schedule, err.Error()))
	}

	return allErrs
}
開發者ID:RyanBinfeng,項目名稱:kubernetes,代碼行數:9,代碼來源:validation.go

示例6: Validate

// Validate returns error if cron entry dosn't match crontab format
func (c *CronSchedule) Validate() error {
	if c.entry == "" {
		return ErrMissingCronEntry
	}
	_, err := cron.Parse(c.entry)
	if err != nil {
		return err
	}
	return nil
}
開發者ID:Collinux,項目名稱:snap,代碼行數:11,代碼來源:cron_schedule.go

示例7: Schedule

func Schedule(spec string, job cron.Job) {
	// Look to see if given spec is a key from the Config.
	if strings.HasPrefix(spec, "cron.") {
		confSpec, found := revel.Config.String(spec)
		if !found {
			panic("Cron spec not found: " + spec)
		}
		spec = confSpec
	}
	MainCron.Schedule(cron.Parse(spec), New(job))
}
開發者ID:adarshaj,項目名稱:revel,代碼行數:11,代碼來源:jobrunner.go

示例8: newJob

func newJob(id string, pri int) *Job {
	sch, _ := cron.Parse("* * * * *")
	// subtract priority from fixed last run, so higher priority jobs were last run further back in time
	t_last_run := time.Unix(1437856044-int64(pri), 0)
	return &Job{
		Id:                  id,
		t_schedule:          sch,
		t_last_run:          &t_last_run,
		scheduling_priority: NormalPriority,
	}
}
開發者ID:byxorna,項目名稱:moroccron,代碼行數:11,代碼來源:priority_queue_test.go

示例9: PutTask

func (k *Keeper) PutTask(name string, t Task) error {
	k.tkmu.Lock()
	defer k.tkmu.Unlock()
	if name != t.Name {
		return errors.New("Task name not correct")
	}
	if _, err := cron.Parse(t.Schedule); err != nil {
		return err
	}
	k.tasks[name] = t
	k.reloadCron()
	return k.save()
}
開發者ID:anley,項目名稱:webcron,代碼行數:13,代碼來源:keeper.go

示例10: validateScheduleFormat

func validateScheduleFormat(schedule string, fldPath *field.Path) field.ErrorList {
	allErrs := field.ErrorList{}
	// TODO soltysh: this should be removed when https://github.com/robfig/cron/issues/58 is fixed
	tmpSchedule := schedule
	if len(schedule) > 0 && schedule[0] != '@' {
		tmpSchedule = "0 " + schedule
	}
	if _, err := cron.Parse(tmpSchedule); err != nil {
		allErrs = append(allErrs, field.Invalid(fldPath, schedule, err.Error()))
	}

	return allErrs
}
開發者ID:cheld,項目名稱:kubernetes,代碼行數:13,代碼來源:validation.go

示例11: UpdateSchedule

func UpdateSchedule(s *spec.Schedule) error {
	_, err := cron.Parse(s.String())
	if err != nil {
		return err
	}

	if err = gDb.UpdateSchedule(s); err != nil {
		return err
	}

	schedules.Stop()
	return initCron()
}
開發者ID:sethjback,項目名稱:gobl,代碼行數:13,代碼來源:schedules.go

示例12: getRecentUnmetScheduleTimes

// getRecentUnmetScheduleTimes gets a slice of times (from oldest to latest) that have passed when a Job should have started but did not.
//
// If there are too many (>100) unstarted times, just give up and return an empty slice.
// If there were missed times prior to the last known start time, then those are not returned.
func getRecentUnmetScheduleTimes(sj batch.ScheduledJob, now time.Time) ([]time.Time, error) {
	starts := []time.Time{}
	tmpSched := addSeconds(sj.Spec.Schedule)
	sched, err := cron.Parse(tmpSched)
	if err != nil {
		return starts, fmt.Errorf("Unparseable schedule: %s : %s", sj.Spec.Schedule, err)
	}
	var earliestTime time.Time
	if sj.Status.LastScheduleTime != nil {
		earliestTime = sj.Status.LastScheduleTime.Time
	} else {
		// If none found, then this is either a recently created scheduledJob,
		// or the active/completed info was somehow lost (contract for status
		// in kubernetes says it may need to be recreated), or that we have
		// started a job, but have not noticed it yet (distributed systems can
		// have arbitrary delays).  In any case, use the creation time of the
		// ScheduledJob as last known start time.
		earliestTime = sj.ObjectMeta.CreationTimestamp.Time
	}

	if earliestTime.After(now) {
		return []time.Time{}, nil
	}

	for t := sched.Next(earliestTime); !t.After(now); t = sched.Next(t) {
		starts = append(starts, t)
		// An object might miss several starts.  For example, if
		// controller gets wedged on friday at 5:01pm when everyone has
		// gone home, and someone comes in on tuesday AM and discovers
		// the problem and restarts the controller, then all the hourly
		// jobs, more than 80 of them for one hourly scheduledJob, should
		// all start running with no further intervention (if the scheduledJob
		// allows concurrency and late starts).
		//
		// However, if there is a bug somewhere, or incorrect clock
		// on controller's server or apiservers (for setting creationTimestamp)
		// then there could be so many missed start times (it could be off
		// by decades or more), that it would eat up all the CPU and memory
		// of this controller. In that case, we want to not try to list
		// all the misseded start times.
		//
		// I've somewhat arbitrarily picked 100, as more than 80, but
		// but less than "lots".
		if len(starts) > 100 {
			// We can't get the most recent times so just return an empty slice
			return []time.Time{}, fmt.Errorf("Too many missed start times to list")
		}
	}
	return starts, nil
}
開發者ID:CodeJuan,項目名稱:kubernetes,代碼行數:54,代碼來源:utils.go

示例13: AddTask

func (k *Keeper) AddTask(t Task) error {
	k.tkmu.Lock()
	defer k.tkmu.Unlock()
	if _, exists := k.tasks[t.Name]; exists {
		return errors.New("Task name duplicate: " + t.Name)
	}
	if _, err := cron.Parse(t.Schedule); err != nil {
		return err
	}
	t.Enabled = true
	k.tasks[t.Name] = t
	k.reloadCron()
	return k.save()
}
開發者ID:anley,項目名稱:webcron,代碼行數:14,代碼來源:keeper.go

示例14: getNextStartTimeAfter

// getNextStartTimeAfter gets the latest scheduled start time that is less than "now", or an error.
func getNextStartTimeAfter(schedule string, now time.Time) (time.Time, error) {
	// Using robfig/cron for cron scheduled parsing and next runtime
	// computation. Not using the entire library because:
	// - I want to detect when we missed a runtime due to being down.
	//   - How do I set the time such that I can detect the last known runtime?
	// - I guess the functions could launch a go-routine to start the job and
	// then return.
	// How to handle concurrency control.
	// How to detect changes to schedules or deleted schedules and then
	// update the jobs?
	sched, err := cron.Parse(schedule)
	if err != nil {
		return time.Unix(0, 0), fmt.Errorf("Unparseable schedule: %s : %s", schedule, err)
	}
	return sched.Next(now), nil
}
開發者ID:eljefedelrodeodeljefe,項目名稱:kubernetes,代碼行數:17,代碼來源:utils.go

示例15: Schedule

func Schedule(spec string, job cron.Job) error {
	// Look to see if given spec is a key from the Config.
	if strings.HasPrefix(spec, "cron.") {
		confSpec, found := revel.Config.String(spec)
		if !found {
			panic("Cron spec not found: " + spec)
		}
		spec = confSpec
	}
	sched, err := cron.Parse(spec)
	if err != nil {
		return err
	}
	MainCron.Schedule(sched, New(job))
	return nil
}
開發者ID:elvislei,項目名稱:revel,代碼行數:16,代碼來源:jobrunner.go


注:本文中的github.com/robfig/cron.Parse函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。