/
sleep.go
36 lines (29 loc) · 1.03 KB
/
sleep.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package adapters
import (
"time"
"github.com/smartcontractkit/chainlink/core/logger"
"github.com/smartcontractkit/chainlink/core/store"
"github.com/smartcontractkit/chainlink/core/store/models"
"github.com/smartcontractkit/chainlink/core/utils"
)
// Sleep adapter allows a job to do nothing for some amount of wall time.
type Sleep struct {
Until models.AnyTime `json:"until"`
}
// TaskType returns the type of Adapter.
func (adapter *Sleep) TaskType() models.TaskType {
return TaskTypeSleep
}
// Perform returns the input RunResult after waiting for the specified Until parameter.
func (adapter *Sleep) Perform(input models.RunInput, str *store.Store) models.RunOutput {
duration := adapter.Duration()
if duration > 0 {
logger.Debugw("Task sleeping...", "duration", duration)
<-str.Clock.After(duration)
}
return models.NewRunOutputComplete(models.JSON{})
}
// Duration returns the amount of sleeping this task should be paused for.
func (adapter *Sleep) Duration() time.Duration {
return utils.DurationFromNow(adapter.Until.Time)
}