Skip to content

Commit 1524af1

Browse files
committed
fix bugs.
fix mongo engine.go set job info bug. avoid job attribute coverage, only set some of the necessary fields. set: stat, execerr, execat, nextat.
1 parent 8eb8c90 commit 1524af1

6 files changed

Lines changed: 33 additions & 23 deletions

File tree

api/handler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ func postLogs(c *Context) error {
158158
ContactInfo: []string{notifyOpt.To},
159159
JobResult: notify.JobResult{
160160
JobName: job.Name,
161+
Directory: request.JobLog.WorkDir,
161162
Location: job.Location,
162163
Server: request.JobLog.IpAddr,
163164
Execat: execAt,
@@ -169,7 +170,7 @@ func postLogs(c *Context) error {
169170
},
170171
}
171172
notifySender := c.Get("NotifySender").(*notify.NotifySender)
172-
notifySender.AddJobNotifyEvent("job notify.", watchJobNotify)
173+
notifySender.AddJobNotifyEvent("This Job Has Been Executed.", watchJobNotify)
173174
}
174175
}
175176
response.SetContent(ErrRequestAccepted.Error())

cache/cache.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -408,21 +408,6 @@ func (cacheRepository *CacheRepository) SetJobAction(location string, jobid stri
408408
}
409409
}
410410

411-
//SetJobNextAt is exported
412-
func (cacheRepository *CacheRepository) SetJobNextAt(jobid string, nextat time.Time) {
413-
414-
logger.INFO("[#cache#] set job nextat, %s %s", jobid, nextat)
415-
job := cacheRepository.GetJob(jobid)
416-
if job != nil {
417-
if len(job.Schedule) > 0 {
418-
job.Stat = models.STATE_STOPED
419-
job.NextAt = nextat
420-
logger.INFO("[#cache#] set job %s nextat to %s, execat %s, state %d", jobid, job.NextAt, job.ExecAt, job.Stat)
421-
cacheRepository.storageDriver.SetJob(job)
422-
}
423-
}
424-
}
425-
426411
//SetJobState is exported
427412
func (cacheRepository *CacheRepository) SetJobState(jobid string, state int) {
428413

@@ -438,11 +423,19 @@ func (cacheRepository *CacheRepository) SetJobState(jobid string, state int) {
438423
}
439424
}
440425

441-
//SetJobLog is exported
442-
func (cacheRepository *CacheRepository) SetJobLog(joblog *models.JobLog) {
426+
//SetJobNextAt is exported
427+
func (cacheRepository *CacheRepository) SetJobNextAt(jobid string, nextat time.Time) {
443428

444-
logger.INFO("[#cache#] set job log, %s %d", joblog.JobId, joblog.Stat)
445-
cacheRepository.storageDriver.SetJobLog(joblog)
429+
logger.INFO("[#cache#] set job nextat, %s %s", jobid, nextat)
430+
job := cacheRepository.GetJob(jobid)
431+
if job != nil {
432+
if len(job.Schedule) > 0 {
433+
job.Stat = models.STATE_STOPED
434+
job.NextAt = nextat
435+
logger.INFO("[#cache#] set job %s nextat to %s, execat %s, state %d", jobid, job.NextAt, job.ExecAt, job.Stat)
436+
cacheRepository.storageDriver.SetJob(job)
437+
}
438+
}
446439
}
447440

448441
//SetJobExecute is exported
@@ -467,6 +460,13 @@ func (cacheRepository *CacheRepository) SetJobExecute(jobid string, state int, e
467460
}
468461
}
469462

463+
//SetJobLog is exported
464+
func (cacheRepository *CacheRepository) SetJobLog(joblog *models.JobLog) {
465+
466+
logger.INFO("[#cache#] set job log, %s %d", joblog.JobId, joblog.Stat)
467+
cacheRepository.storageDriver.SetJobLog(joblog)
468+
}
469+
470470
//GetWorker is exported
471471
func (cacheRepository *CacheRepository) GetWorker(key string) *Worker {
472472

cache/driver/mongo/engine.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ func (engine *Engine) putJob(job *models.Job) error {
251251
session := engine.getSession()
252252
defer session.Close()
253253
return session.DB(engine.DataBase).C(SYS_JOBS).
254-
Update(M{"jobid": job.JobId}, job)
254+
Update(M{"jobid": job.JobId}, M{"$set": M{
255+
"stat": job.Stat,
256+
"execerr": job.ExecErr,
257+
"execat": job.ExecAt,
258+
"nextat": job.NextAt}})
255259
}
256260

257261
func (engine *Engine) postJobLog(jobLog *models.JobLog) error {

etc/jobserver.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ cache:
2626
options: [
2727
"maxPoolSize=20",
2828
"replicaSet=mgoCluster",
29-
#"authSource=admin"
29+
#"authSource=admin"
3030
]
3131
notifications:
3232
endpoints:

notify/templates/job.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#b1ebff" style="padding: 0 10px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #333;">
3737
<tr>
3838
<td colspan="2" style="padding:0 10px;">
39-
<a href="task.newegg.org" target="_blank" style=" color: #17627c; text-decoration: none;">
39+
<a href="#" target="_blank" style=" color: #17627c; text-decoration: none;">
4040
<div>
4141
<strong style="font-size: 40px; color: white; text-shadow: 3px 3px 3px gray; filter: dropshadow(color=#000000, offx=2, offy=2);">Cloud</strong>
4242
<strong style="font-size: 60px; text-shadow: 3px 3px 3px gray; filter: dropshadow(color=#000000, offx=2, offy=2);">Task</strong>
@@ -66,6 +66,10 @@
6666
<td class="title"><strong>Job name</strong></td>
6767
<td class="content"><strong>{{.WatchJobNotify.JobName}}</strong></td>
6868
</tr>
69+
<tr>
70+
<td class="title"><strong>Directory</strong></td>
71+
<td class="content"><strong>{{.WatchJobNotify.Directory}}</strong></td>
72+
</tr>
6973
<tr>
7074
<td class="title"><strong>Location</strong></td>
7175
<td class="content"><strong>{{.WatchJobNotify.Location}}</strong></td>

notify/typedef.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func (location *WatchLocation) AddContactInfo(value string) {
6464
//JobResult is exported
6565
type JobResult struct {
6666
JobName string
67+
Directory string
6768
Location string
6869
Server string
6970
Execat string

0 commit comments

Comments
 (0)