timed_queue.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package workqueue
  14. import "time"
  15. type TimedWorkQueue struct {
  16. *Type
  17. }
  18. type TimedWorkQueueItem struct {
  19. StartTime time.Time
  20. Object interface{}
  21. }
  22. func NewTimedWorkQueue() *TimedWorkQueue {
  23. return &TimedWorkQueue{New()}
  24. }
  25. // Add adds the obj along with the current timestamp to the queue.
  26. func (q TimedWorkQueue) Add(timedItem *TimedWorkQueueItem) {
  27. q.Type.Add(timedItem)
  28. }
  29. // Get gets the obj along with its timestamp from the queue.
  30. func (q TimedWorkQueue) Get() (timedItem *TimedWorkQueueItem, shutdown bool) {
  31. origin, shutdown := q.Type.Get()
  32. if origin == nil {
  33. return nil, shutdown
  34. }
  35. timedItem, _ = origin.(*TimedWorkQueueItem)
  36. return timedItem, shutdown
  37. }
  38. func (q TimedWorkQueue) Done(timedItem *TimedWorkQueueItem) error {
  39. q.Type.Done(timedItem)
  40. return nil
  41. }