Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Commit

Permalink
more robust get/set of run loci
Browse files Browse the repository at this point in the history
  • Loading branch information
scottleedavis committed May 11, 2019
1 parent f63af2c commit a2ddcf7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
1 change: 0 additions & 1 deletion server/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (p *Plugin) OnDeactivate() error {

func (p *Plugin) OnConfigurationChange() error {
p.ServerConfig = p.API.GetConfig()
//p.URL = "http://127.0.0.1" + fmt.Sprintf("%s", *p.ServerConfig.ServiceSettings.ListenAddress)
p.URL = fmt.Sprintf("%s", *p.ServerConfig.ServiceSettings.SiteURL)
return nil
}
Expand Down
37 changes: 21 additions & 16 deletions server/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,12 @@ func (p *Plugin) InteractiveSchedule(triggerId string, user *model.User) {
}

func (p *Plugin) Run() {

hostname, _ := os.Hostname()
bytes, bErr := p.API.KVGet(TriggerHostName)
if bErr != nil {
p.API.LogError("failed KVGet %s", bErr)
return
}
if string(bytes) != "" && string(bytes) != hostname {
return
}
p.API.KVSet(TriggerHostName, []byte(hostname))

p.Stop()
p.getAndSetLock()
if !p.running {
p.running = true
p.runner()
}

}

func (p *Plugin) Stop() {
Expand All @@ -200,13 +189,29 @@ func (p *Plugin) Stop() {
}

func (p *Plugin) runner() {

go func() {
<-time.NewTimer(time.Second).C
p.TriggerReminders()
if !p.running {
if !p.running && !p.getAndSetLock() {
return
}
p.TriggerReminders()
p.runner()
}()
}

func (p *Plugin) getAndSetLock() bool {
hostname, _ := os.Hostname()
bytes, bErr := p.API.KVGet(TriggerHostName)
if bErr != nil {
p.API.LogError("failed KVGet %s", bErr)
return false
}
if string(bytes) != "" && string(bytes) != hostname {
return false
} else if string(bytes) == hostname {
return true
}
p.API.KVSet(TriggerHostName, []byte(hostname))
return true

}

0 comments on commit a2ddcf7

Please sign in to comment.