mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
add sync_status field to containers table
This commit is contained in:
@@ -20,6 +20,12 @@ const (
|
||||
EventsDebounceInterval = 100 * time.Millisecond
|
||||
// SyncInterval defines a regular interval to sync containers to the cluster store.
|
||||
SyncInterval = 30 * time.Second
|
||||
|
||||
// SyncStatusSynced indicates that a container record is synchronised with the Docker state.
|
||||
SyncStatusSynced = "synced"
|
||||
// SyncStatusOutdated indicates that a container record may be outdated, for example, due to being unable
|
||||
// to retrieve the container's state from the Docker daemon or when the machine is being stopped or restarted.
|
||||
SyncStatusOutdated = "outdated"
|
||||
)
|
||||
|
||||
type Manager struct {
|
||||
@@ -91,6 +97,7 @@ func (d *Manager) WatchAndSyncContainers(ctx context.Context, store *store.Store
|
||||
select {
|
||||
case e := <-eventCh:
|
||||
switch e.Action {
|
||||
// Actions that may trigger a container state change.
|
||||
case events.ActionStart,
|
||||
events.ActionStop,
|
||||
events.ActionPause,
|
||||
|
||||
@@ -188,16 +188,15 @@ func (nc *networkController) prepareAndWatchDocker(ctx context.Context) error {
|
||||
}
|
||||
|
||||
if err = manager.EnsureUncloudNetwork(ctx, nc.state.Network.Subnet); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("ensure Docker network: %w", err)
|
||||
}
|
||||
slog.Info("Docker network configured.")
|
||||
|
||||
slog.Info("Watching Docker containers and syncing them to the cluster store.")
|
||||
slog.Info("Watching Docker containers and syncing them to cluster store.")
|
||||
// Retry to watch and sync containers until the context is done.
|
||||
boff := backoff.WithContext(backoff.NewExponentialBackOff(
|
||||
backoff.WithInitialInterval(100*time.Millisecond),
|
||||
backoff.WithMaxInterval(5*time.Second),
|
||||
// Retry indefinitely.
|
||||
backoff.WithMaxElapsedTime(0),
|
||||
), ctx)
|
||||
watchAndSync := func() error {
|
||||
|
||||
@@ -23,6 +23,8 @@ CREATE TABLE containers
|
||||
machine_id TEXT NOT NULL DEFAULT '',
|
||||
service_id TEXT AS (json_extract(container, '$.Labels."uncloud.service.id"')),
|
||||
service_name TEXT AS (json_extract(container, '$.Labels."uncloud.service.name"')),
|
||||
-- sync_status indicates if the record reflects the actual Docker state of the container.
|
||||
sync_status TEXT NOT NULL DEFAULT '',
|
||||
-- updated_at is the last time the record was updated.
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT '1970-01-01 00:00:00'
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user