2
0
mirror of https://github.com/hibiken/asynq.git synced 2026-04-20 01:05:51 +08:00

Add hearbeater

This commit is contained in:
Ken Hibino
2020-01-31 06:48:58 -08:00
parent 489e695433
commit d03fa34eaf
8 changed files with 293 additions and 9 deletions

View File

@@ -346,3 +346,29 @@ func (r *RDB) forwardSingle(src, dst string) error {
return script.Run(r.client,
[]string{src, dst}, now).Err()
}
// WriteProcessStatus writes process information to redis with expiration
// set to the value ttl.
func (r *RDB) WriteProcessStatus(ps *base.ProcessStatus, ttl time.Duration) error {
bytes, err := json.Marshal(ps)
if err != nil {
return err
}
key := base.ProcessStatusKey(ps.Host, ps.PID)
return r.client.Set(key, string(bytes), ttl).Err()
}
// ReadProcessStatus reads process information stored in redis.
func (r *RDB) ReadProcessStatus(host string, pid int) (*base.ProcessStatus, error) {
key := base.ProcessStatusKey(host, pid)
data, err := r.client.Get(key).Result()
if err != nil {
return nil, err
}
var ps base.ProcessStatus
err = json.Unmarshal([]byte(data), &ps)
if err != nil {
return nil, err
}
return &ps, nil
}