Skip to content

Commit

Permalink
Merge pull request #8 from Famcache/fix/2.0.1
Browse files Browse the repository at this point in the history
Disconnect: Cleanup Jobs after disconnect
  • Loading branch information
shahen94 authored Jun 29, 2024
2 parents 43b9c8e + 7f790cc commit 6d0f5a7
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 14 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.0
2.0.1
2 changes: 1 addition & 1 deletion domain/jobs/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ type JobsManager interface {
Add(peerId string, delay uint64, isPeriodic bool) string
Get(id string) (Job, bool)
Cancel(id string)
Jobs() []Job
Jobs() *map[string]Job
Chan() <-chan Job
}
2 changes: 1 addition & 1 deletion pkg/actor/actor_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (actor *Actor) DisconnectPeer(peer connection.Peer) {
actor.peers.Remove(peer)
jobs := actor.jobs.Jobs()

for _, job := range jobs {
for _, job := range *jobs {
if job.PeerId() == peer.ID() {
actor.jobs.Cancel(job.ID())
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/actor/register_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ func (actor *Actor) RegisterJob(peer connection.Peer, query command.JobCommand)

logger.Info(fmt.Sprintf("Job registered with id %s", id))

reply := fmt.Sprintf("%s %s", query.ID(), id)

query.ReplyOK(peer.Conn(), reply)
query.ReplyOK(peer.Conn(), id)
}
10 changes: 2 additions & 8 deletions pkg/jobs/manager_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ func (jm *JobsManager) Chan() <-chan job.Job {
return jm.triggerChan
}

func (jm *JobsManager) Jobs() []job.Job {
jobs := make([]job.Job, len(jm.jobs))

for _, job := range jm.jobs {
jobs = append(jobs, job)
}

return jobs
func (jm *JobsManager) Jobs() *map[string]mJob.Job {
return &jm.jobs
}

0 comments on commit 6d0f5a7

Please sign in to comment.