How to use UpdateExecTime method of result Package

Best Gauge code snippet using result.UpdateExecTime

job.go

Source:job.go Github

copy

Full Screen

1package job2import (3 "Coot/core/dbUtil"4 "Coot/core/exec"5 "Coot/error"6 "Coot/utils/send"7 "github.com/domgoer/gotask"8 "strconv"9 "strings"10 "time"11)12type Task struct {13 /*14 * Id 数据库ID15 * Name 任务名称16 * TaskId 任务ID 添加的时候为空17 * TimeType 执行类型 1 秒执行,2 分钟执行,3 小时执行 ,4 每天指定时间执行,5 每月指定天和时间执行,6 年执行18 * Time 周期时间19 * ScriptType 脚本语言20 * ScriptPath 脚本路径21 */22 Id string23 Name string24 TaskId string25 TimeType string26 Time string27 ScriptType string28 ScriptPath string29 AlertType string30 AlertRecMail string31}32type Logs struct {33 /*34 * Id 数据库ID35 * TskName 任务名称36 * TaskId 任务ID 添加的时候为空37 * TimeType 执行类型 1 秒执行,2 分钟执行,3 小时执行 ,4 每天指定时间执行,5 每月指定天和时间执行,6 年执行38 * LogType 日志类型39 * Cmd 脚本语言40 * Status 日志状态 -1执行失败 0开始执行 1执行成功41 */42 Id string43 TaskName string44 Content string45 CreatedAt string46 Cmd string47 TaskId string48 TimeType string49 PreId int6450 LogType int51 Status int52}53var (54 LogOff bool //日志开关55)56func updateExecTime(id string) {57 sql := `58 UPDATE coot_tasks59 SET last_exec_time = ?60 WHERE61 id = ?;62 `63 currTimeStr := time.Now().Format("2006-01-02 15:04:05")64 dbUtil.Update(sql, currTimeStr, id)65}66/*写入日志*/67func writerLogs(log Logs)int64{68 //关闭状态则不记录69 if !LogOff{70 return 071 }72 sql:=`INSERT INTO coot_logs ( 73 task_id,74 task_name,75 content,76 cmd,77 time_type,78 status,79 pre_id,80 created_at81 )82 VALUES83 (?,?,?,?,?,?,?,?);`84 return dbUtil.Insert(sql,log.TaskId,log.TaskName,log.Content,log.Cmd,log.TimeType,log.Status,log.PreId,time.Now().Format("2006-01-02 15:04:05"))85}86// 执行任务87func execute(t *Task) {88 var id = t.Id89 var cmd string90 // 拼接命令91 if t.ScriptType == "Python" {92 cmd = "python " + t.ScriptPath93 } else if t.ScriptType == "Shell" {94 cmd = "sh " + t.ScriptPath95 }96 // 开始执行任务97 PreId:= writerLogs(Logs{ TaskId:t.Id,TaskName:t.Name,Cmd:cmd,TimeType:t.TimeType,Status:0,Content:"开始执行"})98 result, err := exec.Execute(cmd)99 if err != nil {100 go writerLogs(Logs{PreId:PreId, TaskId:t.Id,TaskName:t.Name,Cmd:cmd,TimeType:t.TimeType,Status:-1,Content:"执行失败"})101 } else {102 go writerLogs(Logs{PreId:PreId, TaskId:t.Id,TaskName:t.Name,Cmd:cmd,TimeType:t.TimeType,Status:1,Content:"执行成功:"+result})103 //执行通知104 go notice(t, result)105 }106 // 更新任务执行时间107 updateExecTime(id)108}109// 消息通知110func notice(t *Task, result string) {111 // AlertType 格式,mail,pushBullet,alertOver,fangTang112 arr := strings.Split(t.AlertType, ",")113 if len(arr) > 0 {114 for _, v := range arr {115 sql := `select status,info from coot_setting where type=?;`116 isAlertStatus := dbUtil.Query(sql,v)117 status := strconv.FormatInt(isAlertStatus[0]["status"].(int64), 10)118 r := strings.Split(result, "&&")119 // 判断总开关是否开启// 判断脚本 code 是否 为 0120 if status=="1"&&len(r)>0&&r[0]=="0"{121 // 判断是否开启邮箱通知122 if v == "mail" {123 recList := strings.Split(t.AlertRecMail, ",")124 send.SendMail(recList, "Coot["+t.Name+"]提醒你", r[1], isAlertStatus)125 }126 // 判断是否开启 alertOver 通知127 if v == "alertOver" {128 send.SendAlertOver(isAlertStatus, "Coot["+t.Name+"]提醒你", r[1])129 }130 // 判断是否开启 pushBullet 通知131 if v == "pushBullet" {132 send.SendPushBullet(isAlertStatus, "Coot["+t.Name+"]提醒你", r[1])133 }134 // 判断是否开启 方糖 通知135 if v == "fangTang" {136 send.SendFangTang(isAlertStatus, "Coot["+t.Name+"]提醒你", r[1])137 }138 }139 }140 }141}142func mTask(t *Task, typs string) string {143 var taskId string144 // 创建任务145 switch t.TimeType {146 case "1":147 // 秒执行148 number, err := strconv.Atoi(t.Time)149 error.Check(err, "秒时间格式化失败")150 if typs == "add" {151 task := gotask.NewTask(time.Second*time.Duration(number), func() { execute(t) })152 gotask.AddToTaskList(task)153 taskId = task.ID()154 } else if typs == "update" {155 gotask.ChangeInterval(t.TaskId, time.Second*time.Duration(number))156 }157 case "2":158 // 分钟执行159 number, err := strconv.Atoi(t.Time)160 error.Check(err, "分钟时间格式化失败")161 if typs == "add" {162 task := gotask.NewTask(time.Minute*time.Duration(number), func() { execute(t) })163 gotask.AddToTaskList(task)164 taskId = task.ID()165 } else if typs == "update" {166 gotask.ChangeInterval(t.TaskId, time.Minute*time.Duration(number))167 }168 case "3":169 // 小时执行170 number, err := strconv.Atoi(t.Time)171 error.Check(err, "小时时间格式化失败")172 if typs == "add" {173 task := gotask.NewTask(time.Hour*time.Duration(number), func() { execute(t) })174 gotask.AddToTaskList(task)175 taskId = task.ID()176 } else if typs == "update" {177 gotask.ChangeInterval(t.TaskId, time.Hour*time.Duration(number))178 }179 case "4":180 // 天执行181 task, err := gotask.NewDayTask(t.Time, func() { execute(t) })182 error.Check(err, "")183 gotask.AddToTaskList(task)184 taskId = task.ID()185 case "5":186 // 月执行187 task, err := gotask.NewMonthTask(t.Time, func() { execute(t) })188 error.Check(err, "")189 taskId = task.ID()190 case "6":191 // 年执行192 task := gotask.NewTask(time.Second*2, func() { execute(t) })193 gotask.AddToTaskList(task)194 taskId = task.ID()195 }196 return taskId197}198// 创建定时任务199func AddJob(t *Task) string {200 // 创建任务201 taskId := mTask(t, "add")202 // 返回 任务id203 return taskId204}205// 停止定时任务206func StopJob(taskId string) {207 // 停止任务208 gotask.Stop(taskId)209}210// 更新任务运行时间211func UpdateJobTime(t *Task) {212 mTask(t, "update")213}...

Full Screen

Full Screen

suiteResult.go

Source:suiteResult.go Github

copy

Full Screen

...54}55func (sr *SuiteResult) AddUnhandledError(err error) {56 sr.UnhandledErrors = append(sr.UnhandledErrors, err)57}58func (sr *SuiteResult) UpdateExecTime(startTime time.Time) {59 sr.ExecutionTime = int64(time.Since(startTime) / 1e6)60}61func (sr *SuiteResult) AddSpecResult(specResult *SpecResult) {62 if specResult.IsFailed {63 sr.IsFailed = true64 sr.SpecsFailedCount++65 }66 sr.ExecutionTime += specResult.ExecutionTime67 sr.SpecResults = append(sr.SpecResults, specResult)68}69func (sr *SuiteResult) AddSpecResults(specResults []*SpecResult) {70 for _, result := range specResults {71 sr.AddSpecResult(result)72 }...

Full Screen

Full Screen

UpdateExecTime

Using AI Code Generation

copy

Full Screen

1I have a file called test.py which is in the same directory as main.py. I want to import test.py into main.py. I tried to do the following:2from test import test3Traceback (most recent call last):4 from test import test5ImportError: cannot import name 'test' from 'test' (unknown location)6Traceback (most recent call last):7 import test8Traceback (most recent call last):9 import main10Traceback (most recent call last):11 import test12Traceback (most recent call last):13 import test

Full Screen

Full Screen

UpdateExecTime

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4}5import (6func main() {7 fmt.Println("Hello World")8}9import (10func main() {11 fmt.Println("Hello World")12}13import (14func main() {15 fmt.Println("Hello World")16}17import (18func main() {19 fmt.Println("Hello World")20}21import (22func main() {23 fmt.Println("Hello World")24}25import (26func main() {27 fmt.Println("Hello World")28}29import (30func main() {31 fmt.Println("Hello World")32}33import (34func main() {35 fmt.Println("Hello World")36}37import (38func main() {39 fmt.Println("Hello World")40}41import (42func main() {43 fmt.Println("Hello World")44}45import (46func main() {47 fmt.Println("Hello World")48}

Full Screen

Full Screen

UpdateExecTime

Using AI Code Generation

copy

Full Screen

1import (2type result struct {3}4func (r *result) UpdateExecTime(d time.Duration) {5}6func (r *result) String() string {7 return fmt.Sprintf("Exec Time: %v", r.execTime)8}9func main() {10 r := result{}11 r.UpdateExecTime(100 * time.Millisecond)12 fmt.Println(r)13}

Full Screen

Full Screen

UpdateExecTime

Using AI Code Generation

copy

Full Screen

1import (2type Result struct {3}4var (5func (r *Result) UpdateExecTime(d time.Duration) {6}7func main() {8 wg.Add(1)9 go func() {10 defer wg.Done()11 time.Sleep(2 * time.Second)12 r.UpdateExecTime(2 * time.Second)13 }()14 wg.Wait()15 fmt.Println(r.ExecTime)16}

Full Screen

Full Screen

UpdateExecTime

Using AI Code Generation

copy

Full Screen

1func UpdateExecTime() {2 println("path: 1.go")3}4func UpdateExecTime() {5 println("path: 2.go")6}7func UpdateExecTime() {8 println("path: 3.go")9}10import (11func main() {12 result.UpdateExecTime()13}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful