本文整理汇总了Golang中github.com/badoo/thunder/db.LazyTrx.Exec方法的典型用法代码示例。如果您正苦于以下问题:Golang LazyTrx.Exec方法的具体用法?Golang LazyTrx.Exec怎么用?Golang LazyTrx.Exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/badoo/thunder/db.LazyTrx
的用法示例。
在下文中一共展示了LazyTrx.Exec方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例14: setRunAccepted
func setRunAccepted(tx *db.LazyTrx, className string) (err error) {
_, err = tx.Exec(QUERY_SET_RUN_ACCEPTED, "class_name", className)
return
}
示例15: resetRunRequest
func resetRunRequest(tx *db.LazyTrx, className string) (err error) {
_, err = tx.Exec(QUERY_RESET_RUN_REQUEST, "class_name", className)
return
}