当前位置: 首页>>代码示例>>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;未经允许,请勿转载。