mirror of
https://github.com/nxshock/gron.git
synced 2024-11-27 03:41:00 +05:00
Rename mutex
This commit is contained in:
parent
6c38e60b47
commit
a0eceeee64
18
job.go
18
job.go
@ -20,7 +20,7 @@ type JobConfig struct {
|
|||||||
Description string
|
Description string
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentRunningJobsMutex sync.RWMutex
|
var globalMutex sync.RWMutex
|
||||||
|
|
||||||
func readJob(filePath string) (*Job, error) {
|
func readJob(filePath string) (*Job, error) {
|
||||||
var jobConfig JobConfig
|
var jobConfig JobConfig
|
||||||
@ -69,10 +69,10 @@ type Job struct {
|
|||||||
func (j *Job) Run() {
|
func (j *Job) Run() {
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
currentRunningJobsMutex.Lock()
|
globalMutex.Lock()
|
||||||
j.CurrentRunningCount++
|
j.CurrentRunningCount++
|
||||||
j.LastStartTime = startTime.Format(timeFormat)
|
j.LastStartTime = startTime.Format(timeFormat)
|
||||||
currentRunningJobsMutex.Unlock()
|
globalMutex.Unlock()
|
||||||
|
|
||||||
jobLogFile, _ := os.OpenFile(filepath.Join(logFilesPath, j.FileName+".txt"), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
|
jobLogFile, _ := os.OpenFile(filepath.Join(logFilesPath, j.FileName+".txt"), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
|
||||||
defer jobLogFile.Close()
|
defer jobLogFile.Close()
|
||||||
@ -94,22 +94,22 @@ func (j *Job) Run() {
|
|||||||
log.WithField("job", j.FileName).Error(err.Error())
|
log.WithField("job", j.FileName).Error(err.Error())
|
||||||
l.WithField("job", j.FileName).Error(err.Error())
|
l.WithField("job", j.FileName).Error(err.Error())
|
||||||
|
|
||||||
currentRunningJobsMutex.Lock()
|
globalMutex.Lock()
|
||||||
j.LastError = err.Error()
|
j.LastError = err.Error()
|
||||||
currentRunningJobsMutex.Unlock()
|
globalMutex.Unlock()
|
||||||
} else {
|
} else {
|
||||||
currentRunningJobsMutex.Lock()
|
globalMutex.Lock()
|
||||||
j.LastError = ""
|
j.LastError = ""
|
||||||
currentRunningJobsMutex.Unlock()
|
globalMutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
endTime := time.Now()
|
endTime := time.Now()
|
||||||
log.WithField("job", j.FileName).Infof("finished (%s)", endTime.Sub(startTime).Truncate(time.Second).String())
|
log.WithField("job", j.FileName).Infof("finished (%s)", endTime.Sub(startTime).Truncate(time.Second).String())
|
||||||
l.Infof("finished (%s)", endTime.Sub(startTime).Truncate(time.Second).String())
|
l.Infof("finished (%s)", endTime.Sub(startTime).Truncate(time.Second).String())
|
||||||
|
|
||||||
currentRunningJobsMutex.Lock()
|
globalMutex.Lock()
|
||||||
j.CurrentRunningCount--
|
j.CurrentRunningCount--
|
||||||
j.LastEndTime = endTime.Format(timeFormat)
|
j.LastEndTime = endTime.Format(timeFormat)
|
||||||
j.LastExecutionDuration = endTime.Sub(startTime).Truncate(time.Second).String()
|
j.LastExecutionDuration = endTime.Sub(startTime).Truncate(time.Second).String()
|
||||||
currentRunningJobsMutex.Unlock()
|
globalMutex.Unlock()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user