예제 #1
0
파일: common.go 프로젝트: badoo/thunder
func getNextJobGenerateTs(className string, firstRun bool, prevTs uint64, settings *ScriptSettings) (nextTs uint64) {
	if !settings.have_next_ts_callback {
		if firstRun {
			nextTs = uint64(time.Now().Unix())
		} else {
			nextTs = prevTs + uint64(settings.repeat)
		}
	} else if settings.next_ts_callback.Callback == "cron" {
		if _, ok := settings.next_ts_callback.Settings["cron"]; !ok {
			log.Warning("'cron' section is absent for next ts callback for " + className)
			return
		}

		now := uint64(time.Now().Unix())

		if firstRun {
			prevTs = now
		}

		nextTs = getNextLaunchTsForCron(prevTs, now, rand.Intn(60), settings.next_ts_callback.Settings["cron"])
	} else {
		log.Warning("Callbacks other than cron are not supported for " + className)
	}

	return
}
예제 #2
0
파일: db.go 프로젝트: badoo/thunder
func (p *LazyTrx) Commit() error {
	if p.level == 0 {
		buf := make([]byte, 5000)
		n := runtime.Stack(buf, false)
		log.Warning("Requested commit for zero level: " + string(buf[0:n]))
	}

	p.level--

	if p.level == 0 && p.tx != nil {
		err := p.tx.Commit()
		DebugPrintln(p.Name, "COMMIT")
		if err != nil {
			return err
		}

		if p.commitCallbacks != nil {
			for _, cb := range p.commitCallbacks {
				cb()
			}
		}

		p.tx = nil
	}

	return nil
}