Skip to content

Commit

Permalink
Update conditional-sync.md (#3660)
Browse files Browse the repository at this point in the history
  • Loading branch information
npentrel authored Nov 7, 2024
1 parent 849da58 commit 136fc4d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions docs/how-tos/conditional-sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ If the builtin data manager is configured with a sync sensor, the data manager w

The following example returns `"should_sync": true` if the current time is in a specified time window, and `"should_sync": false` otherwise.

```go {class="line-numbers linkable-line-numbers" data-line="26,30,31,35"}
```go {class="line-numbers linkable-line-numbers" data-line="26,31,32,37"}
func (s *timeSyncer) Readings(context.Context, map[string]interface{}) (map[string]interface{}, error) {
currentTime := time.Now()
var hStart, mStart, sStart, hEnd, mEnd, sEnd int
Expand All @@ -97,14 +97,16 @@ func (s *timeSyncer) Readings(context.Context, map[string]interface{}) (map[stri
hEnd, mEnd, sEnd, 0, zone)

readings := map[string]interface{}{"should_sync": false}
readings["time"] = currentTime.String()
// If it is between the start and end time, sync.
if currentTime.After(startTime) && currentTime.Before(endTime) {
s.logger.Info("Syncing")
s.logger.Debug("Syncing")
readings["should_sync"] = true
return readings, nil
}

// Otherwise, do not sync.
s.logger.Debug("Not syncing. Current time not in sync window: " + currentTime.String())
return readings, nil
}
```
Expand Down

0 comments on commit 136fc4d

Please sign in to comment.