• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang db.LazyTrx类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/badoo/thunder/db.LazyTrx的典型用法代码示例。如果您正苦于以下问题:Golang LazyTrx类的具体用法?Golang LazyTrx怎么用?Golang LazyTrx使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了LazyTrx类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: batchSetNextGenerateJobTs

func batchSetNextGenerateJobTs(tx *db.LazyTrx, className string, params []NextGenParams, settings *ScriptSettings) (err error) {
	if len(params) == 0 {
		return
	}

	fields := `(class_name, location, next_generate_job_ts, jobs_generated_ts, jobs_finished_ts, init_jobs_ts, finish_jobs_ts, generation_id, settings_id)`
	values := make([]string, 0, len(params))

	for _, par := range params {
		firstRun := !par.JobInfo.jobs_generated_ts.Valid
		var prevTs, nextTs uint64

		if !firstRun {
			prevTs = uint64(par.JobInfo.jobs_generated_ts.Int64)
		}

		nextTs = getNextJobGenerateTs(className, firstRun, prevTs, settings)

		values = append(values, fmt.Sprintf("('%s', '%s', FROM_UNIXTIME(%d), NULL, NULL, NULL, NULL, 1, %d)",
			db.EscapeString(className), db.EscapeString(par.Location), nextTs, settings.id))
	}

	_, err = tx.Exec(
		QUERY_BATCH_SET_NEXT_GENERATE_JOB_TS,
		"fields", fields,
		"values", &db.RawData{Data: strings.Join(values, ", ")})
	return
}
开发者ID:badoo,项目名称:thunder,代码行数:28,代码来源:model.go


示例2: setRunStatusToInit

func setRunStatusToInit(tx *db.LazyTrx, run_id uint64, max_time int) (err error) {
	_, err = tx.Exec(
		QUERY_UPDATE_RUN_STATUS_INIT,
		"max_time", max_time,
		"id", run_id)
	return
}
开发者ID:badoo,项目名称:thunder,代码行数:7,代码来源:model.go


示例3: setMaxFinishedTs

func setMaxFinishedTs(tx *db.LazyTrx, className string, employeeId int64, ts int64) (err error) {
	_, err = tx.Exec(
		QUERY_SET_MAX_FINISHED_TS_NOW,
		"class_name", className,
		"employee_id", employeeId,
		"ts", ts)
	return
}
开发者ID:badoo,项目名称:thunder,代码行数:8,代码来源:model.go


示例4: setNextGenerateJobTs

func setNextGenerateJobTs(tx *db.LazyTrx, className string, settings *ScriptSettings) (err error) {
	nextTs := getNextJobGenerateTs(className, true, 0, settings)

	_, err = tx.Exec(
		QUERY_SET_NEXT_GENERATE_JOB_TS,
		"class_name", className,
		"settings_id", settings.id,
		"next_generate_job_ts", nextTs)
	return
}
开发者ID:badoo,项目名称:thunder,代码行数:10,代码来源:model.go


示例5: clearJobsResultsForLocations

func clearJobsResultsForLocations(tx *db.LazyTrx, className string, locations []string) (err error) {
	if len(locations) == 0 {
		return
	}

	_, err = tx.Exec(
		QUERY_CLEAR_JOB_RESULTS_FOR_LOCATIONS,
		"class_name", className,
		"locations", db.INStr(locations))
	return
}
开发者ID:badoo,项目名称:thunder,代码行数:11,代码来源:model.go


示例6: setJobsGeneratedTs

func setJobsGeneratedTs(tx *db.LazyTrx, className string, locations []string) (err error) {
	if len(locations) == 0 {
		return
	}

	_, err = tx.Exec(
		QUERY_SET_JOBS_GENERATED_TS,
		"class_name", className,
		"locations", db.INStr(locations))
	return
}
开发者ID:badoo,项目名称:thunder,代码行数:11,代码来源:model.go


示例7: setInitJobsTs

func setInitJobsTs(tx *db.LazyTrx, className string, locations []string) (err error) {
	if len(locations) == 0 {
		return
	}

	_, err = tx.Exec(
		QUERY_SET_INIT_JOBS_TS,
		"class_name", className,
		"locations", db.INStr(locations))
	return
}
开发者ID:badoo,项目名称:thunder,代码行数:11,代码来源:model.go


示例8: deleteAddedFromTimetable

func deleteAddedFromTimetable(tx *db.LazyTrx, ids []uint64) error {
	if len(ids) == 0 {
		return nil
	}

	res, err := tx.Exec(QUERY_DELETE_FROM_TIMETABLE, "ids", db.INUint64(ids), "add_where", " AND added_to_queue_ts IS NOT NULL")
	if err != nil {
		return err
	}
	aff, err := res.RowsAffected()
	if err != nil {
		return err
	}
	if aff != int64(len(ids)) {
		return fmt.Errorf("deleteAddedFromTimetable unexpected ttIds deleted count:%d instead of %d ids:%+v", aff, len(ids), ids)
	}
	return nil
}
开发者ID:badoo,项目名称:thunder,代码行数:18,代码来源:model.go


示例9: addToTimetable

// method inserts rows into timetable and sets insert id
func addToTimetable(tx *db.LazyTrx, ttRows []*TimetableEntry) error {
	if len(ttRows) == 0 {
		return nil
	}

	values := make([]string, 0)

	for _, row := range ttRows {
		val := fmt.Sprintf(
			"('%s', %d, %s, '%s', %d, %s, %d, '%s', '%s', %d, FROM_UNIXTIME(%d), FROM_UNIXTIME(%d))",
			db.EscapeString(row.class_name),
			row.default_retry,
			db.QNullInt64(row.repeat).Data,
			row.method,
			row.finished_successfully,
			db.QNullInt64(row.generation_id).Data,
			row.settings_id,
			db.EscapeString(row.location),
			db.EscapeString(row.JobData),
			0,
			row.created,
			row.NextLaunchTs.Int64)

		values = append(values, val)
	}

	res, err := tx.Exec(QUERY_INSERT_INTO_TIMETABLE, "values", &db.RawData{Data: strings.Join(values, ", ")})
	if err != nil {
		return err
	}

	insId, err := res.LastInsertId()
	if err != nil {
		log.Errorf("Could not get insert id even though insert was successfull: %s", err.Error())
		return err
	}

	for _, row := range ttRows {
		row.id = uint64(insId)
		insId += autoIncrementIncrement
	}

	return nil
}
开发者ID:badoo,项目名称:thunder,代码行数:45,代码来源:model.go


示例10: addJobInfo

func addJobInfo(tx *db.LazyTrx, rows []*JobInfoEntry) (err error) {
	if len(rows) == 0 {
		return
	}

	fields := `(class_name, location, next_generate_job_ts, settings_id)`
	values := make([]string, 0, len(rows))

	for _, row := range rows {
		values = append(values, fmt.Sprintf(
			"('%s', '%s', FROM_UNIXTIME(%d), %d)",
			db.EscapeString(row.class_name), db.EscapeString(row.location), row.next_generate_job_ts.Int64, row.settings_id))
	}

	_, err = tx.Exec(
		QUERY_INSERT_INTO_JOB_INFO,
		"fields", fields,
		"values", &db.RawData{Data: strings.Join(values, ",")})
	return
}
开发者ID:badoo,项目名称:thunder,代码行数:20,代码来源:model.go


示例11: deleteFromRunQueue

func deleteFromRunQueue(tx *db.LazyTrx, ids []uint64, prevStatus string) error {
	if len(ids) == 0 {
		return nil
	}

	res, err := tx.Exec(
		QUERY_DELETE_FROM_QUEUE,
		"ids", db.INUint64(ids),
		"status", prevStatus)
	if err != nil {
		return err
	}
	aff, err := res.RowsAffected()
	if err != nil {
		return err
	}
	if aff != int64(len(ids)) {
		return fmt.Errorf("deleteFromRunQueue failed aff:%d expected:%d ids:%+v prevStatus:%s", aff, len(ids), ids, prevStatus)
	}
	return nil
}
开发者ID:badoo,项目名称:thunder,代码行数:21,代码来源:model.go


示例12: logTTFinish

func logTTFinish(tx *db.LazyTrx, row *TimetableEntry, haveOldFinishCount bool, oldFinishCount uint) error {
	var addedToQueueWhere, addedFinishCountWhere string
	if row.added_to_queue_ts.Valid {
		addedToQueueWhere = "AND added_to_queue_ts IS NULL"
	} else {
		addedToQueueWhere = "AND added_to_queue_ts IS NOT NULL"
	}

	if haveOldFinishCount {
		addedFinishCountWhere = fmt.Sprintf("AND finish_count = %d", oldFinishCount)
	} else {
		addedFinishCountWhere = fmt.Sprintf("AND finish_count = %d", row.finish_count-1)
	}

	res, err := tx.Exec(QUERY_UPDATE_TIMETABLE_STATUS,
		"finished_ts", db.QNullInt64(row.finished_ts),
		"next_launch_ts", db.QNullInt64(row.NextLaunchTs),
		"added_to_queue_ts", db.QNullInt64(row.added_to_queue_ts),
		"finish_count", row.finish_count,
		"retry_count", row.retry_count,
		"finished_successfully", row.finished_successfully,
		"id", row.id,
		"add_where", fmt.Sprintf("%s %s", addedToQueueWhere, addedFinishCountWhere))

	if err != nil {
		return err
	}

	aff, err := res.RowsAffected()
	if err != nil {
		return err
	}

	if aff != 1 {
		return fmt.Errorf("unexpected affected rows = %d for tt_row = %+v", aff, row)
	}

	return nil
}
开发者ID:badoo,项目名称:thunder,代码行数:39,代码来源:model.go


示例13: updateRunStatus

func updateRunStatus(tx *db.LazyTrx, run_id uint64, status, prevStatus string) error {
	res, err := tx.Exec(
		QUERY_UPDATE_RUN_STATUS,
		"status", status,
		"prev_status", prevStatus,
		"id", run_id)

	if err != nil {
		return err
	}

	aff, err := res.RowsAffected()
	if err != nil {
		return err
	}

	if aff != 1 {
		return fmt.Errorf("Previous status mismatch for rq row id=%d: tried %s -> %s", run_id, prevStatus, status)
	}

	return nil
}
开发者ID:badoo,项目名称:thunder,代码行数:22,代码来源:model.go


示例14: doCycle

func doCycle() bool {
	var (
		jiRows         map[string]map[string]*JobInfoEntry
		scripts        map[string]*ScriptEntry
		flags          map[string]*FlagEntry
		scriptsRusage  map[string]*ScriptRusageEntry
		classLocTTRows map[string]map[string][]*TimetableEntry
	)

	unifiedStartTs := time.Now().UnixNano()

	startTs := time.Now().UnixNano()
	err := loadFullState(
		&LoadStateFunc{name: "Scripts", fun: func() (err error) { scripts, err = getGroupedScriptsForPlatform(); return }},
		&LoadStateFunc{name: "JobInfo", fun: func() (err error) { jiRows, err = getGroupedJobInfo(); return }},
		&LoadStateFunc{name: "Flags", fun: func() (err error) { flags, err = getFlags(); return }},
		&LoadStateFunc{name: "ScriptsRusage", fun: func() (err error) { scriptsRusage, err = getScriptRusageStats(); return }},
		&LoadStateFunc{name: "ScriptTimetable", fun: func() (err error) { classLocTTRows, err = selectTimetable(); return }})

	if err != nil {
		log.Errorf("Failed to select state in doCycle: %s", err.Error())
		return false
	}

	log.Debugf("Loaded for %.5f sec", float64(time.Now().UnixNano()-startTs)/1e9)

	startTs = time.Now().UnixNano()
	err = loadSettingsFromRows(jiRows, scripts)
	if err != nil {
		log.Errorf("Could not load settings from rows: %s", err.Error())
		return false
	}

	func() {
		allSettingsMutex.Lock()
		defer allSettingsMutex.Unlock()

		for _, row := range scripts {
			row.settings = allSettings[row.settings_id]
		}
	}()

	scriptsMap.Lock()
	scriptsMap.v = scripts
	scriptsMap.Unlock()

	log.Debugf("  Selected %d rows from flags", len(flags))
	log.Debugf("  Selected %d rows from scripts rusage", len(scriptsRusage))
	log.Debugf("Load settings for %.5f sec", float64(time.Now().UnixNano()-startTs)/1e9)

	startTs = time.Now().UnixNano()

	// We should not try to generate jobs for scripts that are not present in Script table
	// But we should not forget settings (e.g. last generation_id) for that script
	for class_name := range jiRows {
		if _, ok := scripts[class_name]; !ok {
			delete(jiRows, class_name)
		}
	}

	log.Debugf("Selected all for %.5f sec", float64(time.Now().UnixNano()-unifiedStartTs)/1e9)

	startTs = time.Now().UnixNano()
	updateLoadEstimates()

	log.Debugf("Load estimates updated for %.5f sec", float64(time.Now().UnixNano()-startTs)/1e9)
	func() {
		rusageInfo.Lock()
		defer rusageInfo.Unlock()
		log.Debugf("Group hosts: %+v", rusageInfo.groupHosts)
	}()

	startTs = time.Now().UnixNano()

	failedLocationsMutex.Lock()
	failedLocations = make(map[string]bool)
	failedLocationsMutex.Unlock()

	success := true

	if len(scripts) > 0 {
		throttle.setIntervalCh <- time.Second / time.Duration(len(scripts))
	}

	trigger(throttle.c, "throttle, start of cycle")

	for className, script := range scripts {
		<-throttle.c

		tx := new(db.LazyTrx)
		err := tx.Begin()
		if err != nil {
			log.Errorf("Could not start transaction in job generate: %s", err.Error())
			success = false
			continue
		}

		have := make(map[string]bool)
		locTtRows := classLocTTRows[className]
		if locTtRows != nil {
//.........这里部分代码省略.........
开发者ID:badoo,项目名称:thunder,代码行数:101,代码来源:jobgen.go


示例15: generateJobs

// haveTTRows must be nil if there are no timetable entries for any location
// otherwise it must have only true entries like map["location"] => true
// probably jobs generation can be simplified, it is just the way it is
func generateJobs(tx *db.LazyTrx, className string, settings *ScriptSettings, jiRows map[string]*JobInfoEntry, haveTTRows map[string]bool, flags *FlagEntry) (add_to_timetable []*TimetableEntry, err error) {
	if haveTTRows != nil && len(haveTTRows) == 0 {
		haveTTRows = nil
	}

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

	add_to_timetable = make([]*TimetableEntry, 0)
	add_job_info := make([]*JobInfoEntry, 0)
	set_finish_jobs := make([]string, 0)
	set_init_jobs := make([]string, 0)
	set_jobs_generated_js := make([]string, 0)
	prepare_next_generation := make([]NextGenParams, 0)

	have_finish_jobs := settings.jobs.Have_finish_jobs
	is_any := (settings.location_type == LOCATION_TYPE_ANY)
	is_temporary := settings.jobs.Temporary
	temporary_can_run := false

	if flags != nil {
		if flags.kill_requested_ts.Valid {
			is_done := (haveTTRows == nil)
			if is_done {
				log.Printf("Class %s is done, all is ok", className)

				if !flags.killed_ts.Valid {
					tx.AddCommitCallback(func() { continueDispatchAfterKill(className) })
					if err = setKilledFlag(tx, className); err != nil {
						return
					}

					if err = prepareNextGeneration(tx, have_finish_jobs, className, settings); err != nil {
						return
					}
				}
			} else {
				log.Printf("Class %s is not done", className)

				startKilling(className)

				// not the best place to put it, but it works
				if err = setMaxFinishedTs(tx, className, flags.kill_request_employee_id.Int64, flags.kill_requested_ts.Int64); err != nil {
					return
				}
			}

			return
		}

		// Stop generating new job generations when we are on pause
		if flags.pause_requested_ts.Valid {
			is_done := generationFinished(className, haveTTRows, jiRows, settings)

			if is_done && !flags.paused_ts.Valid {
				if err = setPausedFlag(tx, className); err != nil {
					return
				}

				flags.paused_ts = sql.NullInt64{Int64: now, Valid: true}
			}

			if !is_any || flags.paused_ts.Valid {
				return
			}
		}

		if is_temporary && flags.run_requested_ts.Valid && is_any {
			// We accepted run request, which means that we already generated jobs
			if flags.run_accepted_ts.Valid {
				if generationFinished(className, haveTTRows, jiRows, settings) {
					if err = resetRunRequest(tx, className); err != nil {
						return
					}

					if err = prepareNextGeneration(tx, have_finish_jobs, className, settings); err != nil {
						return
					}

					return
				}
			} else {
				if err = setRunAccepted(tx, className); err != nil {
					return
				}
			}

			temporary_can_run = true
		}
	}

	if is_temporary && !temporary_can_run || settings.jobs.Type == JOBS_TYPE_NONE {
		return
	}

	locations := make([]string, 0)

	if !is_any {
//.........这里部分代码省略.........
开发者ID:badoo,项目名称:thunder,代码行数:101,代码来源:jobgen.go


示例16: setPausedFlag

func setPausedFlag(tx *db.LazyTrx, className string) (err error) {
	_, err = tx.Exec(
		`UPDATE `+TABLE_SCRIPT_FLAGS+` SET paused_ts = NOW() WHERE class_name = '#class_name#'`,
		"class_name", className)
	return
}
开发者ID:badoo,项目名称:thunder,代码行数:6,代码来源:model.go


示例17: setRunAccepted

func setRunAccepted(tx *db.LazyTrx, className string) (err error) {
	_, err = tx.Exec(QUERY_SET_RUN_ACCEPTED, "class_name", className)
	return
}
开发者ID:badoo,项目名称:thunder,代码行数:4,代码来源:model.go


示例18: resetRunRequest

func resetRunRequest(tx *db.LazyTrx, className string) (err error) {
	_, err = tx.Exec(QUERY_RESET_RUN_REQUEST, "class_name", className)
	return
}
开发者ID:badoo,项目名称:thunder,代码行数:4,代码来源:model.go


示例19: clearJobsResults

func clearJobsResults(tx *db.LazyTrx, className string) (err error) {
	_, err = tx.Exec(
		QUERY_CLEAR_JOB_RESULTS,
		"class_name", className)
	return
}
开发者ID:badoo,项目名称:thunder,代码行数:6,代码来源:model.go


示例20: addToQueueAndDeleteExpired

func addToQueueAndDeleteExpired(tx *db.LazyTrx, rows []*RunQueueEntry, toDelete []*TimetableEntry) error {
	if len(rows) > 0 {
		values := make([]string, 0, len(rows))
		ttIds := make([]uint64, 0, len(rows))

		fields := `(class_name, timetable_id, generation_id, hostname, hostname_idx, job_data, method, created, run_status, waiting_ts, should_init_ts, token, retry_attempt, settings_id)`

		for _, row := range rows {
			ttIds = append(ttIds, uint64(row.timetable_id.Int64))

			val := fmt.Sprint(
				"('"+db.EscapeString(row.ClassName)+"',",
				db.QNullInt64(row.timetable_id).Data, ",",
				row.generation_id.Int64, ",",
				"'"+db.EscapeString(row.hostname)+"',",
				row.hostname_idx, ",",
				"'"+db.EscapeString(row.JobData)+"',",
				"'"+db.EscapeString(row.method)+"',",
				"FROM_UNIXTIME(", row.created.Int64, "),",
				"'"+db.EscapeString(row.RunStatus)+"',",
				"FROM_UNIXTIME(", row.waiting_ts.Int64, "),",
				"FROM_UNIXTIME(", row.should_init_ts.Int64, "),",
				"'"+db.EscapeString(row.token), "',",
				row.retry_attempt, ",",
				row.settings_id, ")")

			values = append(values, val)
		}

		res, err := tx.Exec(QUERY_INSERT_INTO_RUN_QUEUE, "fields", fields, "values", &db.RawData{Data: strings.Join(values, ",")})
		if err != nil {
			return err
		}

		insId, err := res.LastInsertId()
		if err != nil {
			return err
		}

		for _, row := range rows {
			row.Id = uint64(insId)
			insId += autoIncrementIncrement
		}

		sort.Sort(common.UInt64Slice(ttIds))

		res, err = tx.Exec(QUERY_LOG_ADD_TO_QUEUE, "ids", db.INUint64(ttIds))
		if err != nil {
			return err
		}
		aff, err := res.RowsAffected()
		if err != nil {
			return err
		}
		if aff != int64(len(ttIds)) {
			return fmt.Errorf("update ur cache bro aff: %d ttIds:%+v", aff, ttIds)
		}
	}

	if len(toDelete) > 0 {
		ttIds := make([]uint64, 0, len(toDelete))
		for _, row := range toDelete {
			ttIds = append(ttIds, row.id)
		}

		sort.Sort(common.UInt64Slice(ttIds))

		res, err := tx.Exec(QUERY_DELETE_FROM_TIMETABLE, "ids", db.INUint64(ttIds), "add_where", " AND added_to_queue_ts IS NULL")
		if err != nil {
			return err
		}
		aff, err := res.RowsAffected()
		if err != nil {
			return err
		}
		if aff != int64(len(ttIds)) {
			return fmt.Errorf("addToQueueAndDeleteExpired unexpected ttIds deleted count:%d instead of %d ids:%+v", aff, len(ttIds), ttIds)
		}
	}

	return nil
}
开发者ID:badoo,项目名称:thunder,代码行数:82,代码来源:model.go



注:本文中的github.com/badoo/thunder/db.LazyTrx类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang enc.New函数代码示例发布时间:2022-05-24
下一篇:
Golang errors.NewNotFoundError函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap