Fire an event to the websocket when a backup is completed
This commit is contained in:
parent
45d441ac32
commit
222091b68c
|
@ -170,6 +170,14 @@ func (b *Backup) BackupAndNotify() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Emit an event over the socket so we can update the backup in realtime on
|
||||||
|
// the frontend for the server.
|
||||||
|
b.server.Events().PublishJson(BackupCompletedEvent, map[string]interface{}{
|
||||||
|
"uuid": b.Uuid,
|
||||||
|
"sha256_hash": resp.Sha256Hash,
|
||||||
|
"file_size": resp.FileSize,
|
||||||
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,6 +51,17 @@ func (e *EventBus) Publish(topic string, data string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *EventBus) PublishJson(topic string, data interface{}) error {
|
||||||
|
b, err := json.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
e.Publish(topic, string(b))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Subscribe to an emitter topic using a channel.
|
// Subscribe to an emitter topic using a channel.
|
||||||
func (e *EventBus) Subscribe(topic string, ch chan Event) {
|
func (e *EventBus) Subscribe(topic string, ch chan Event) {
|
||||||
e.mu.Lock()
|
e.mu.Lock()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user