// Do specifies the jobFunc that should be called every time the Job runs
Do specifies the jobFunc that should be called every time the Job runs
// Do specifies the jobFunc that should be called every time the Job runs
func (s *Scheduler) Do(jobFun interface{}, params ...interface{}) (*Job, error) {
	job := s.getCurrentJob()
	jobUnit := job.getUnit()
	if job.atTime != 0 && (jobUnit <= hours || jobUnit >= duration) {
		job.error = wrapOrError(job.error, ErrAtTimeNotSupported)
	}
	if len(job.scheduledWeekday) != 0 && jobUnit != weeks {
		job.error = wrapOrError(job.error, ErrWeekdayNotSupported)
	}
	if job.error != nil {
		s.RemoveByReference(job)
		return nil, job.error
	}
	typ := reflect.TypeOf(jobFun)
	if typ.Kind() != reflect.Func {
		s.RemoveByReference(job)
		return nil, ErrNotAFunction
	}
	f := reflect.ValueOf(jobFun)
	if len(params) != f.Type().NumIn() {
		s.RemoveByReference(job)
		job.error = wrapOrError(job.error, ErrWrongParams)
		return nil, job.error
	}
	fname := getFunctionName(jobFun)
	if job.name != fname {
		job.function = jobFun
		job.parameters = params
		job.name = fname
	}
	if s.IsRunning() {
		s.scheduleNextRun(job)
	}
	return job, nil
}
func ( s * Scheduler ) Do ( jobFun interface { } , params ... interface { } ) ( * Job , error ) { job := s . getCurrentJob ( ) jobUnit := job . getUnit ( ) if job . atTime != 0 && ( jobUnit <= hours || jobUnit >= duration ) { job . error = wrapOrError ( job . error , ErrAtTimeNotSupported ) } if len ( job . scheduledWeekday ) != 0 && jobUnit != weeks { job . error = wrapOrError ( job . error , ErrWeekdayNotSupported ) } if job . error != nil { s . RemoveByReference ( job ) return nil , job . error } typ := reflect . TypeOf ( jobFun ) if typ . Kind ( ) != reflect . Func { s . RemoveByReference ( job ) return nil , ErrNotAFunction } f := reflect . ValueOf ( jobFun ) if len ( params ) != f . Type ( ) . NumIn ( ) { s . RemoveByReference ( job ) job . error = wrapOrError ( job . error , ErrWrongParams ) return nil , job . error } fname := getFunctionName ( jobFun ) if job . name != fname { job . function = jobFun job . parameters = params job . name = fname } if s . IsRunning ( ) { s . scheduleNextRun ( job ) } return job , nil }
Do specifies the jobFunc that should be called every time the Job runs
Do specifies the jobFunc that should be called every time the Job runs
// delete the job from the scheduler as this job // cannot be executed // delete the job for the same reason as above // we should not schedule if not running since we cant foresee how long it will take for the scheduler to start