Class: PeriodicScheduler::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/periodic-scheduler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(quantized_space, now, period, keep, &callback) ⇒ Event

Returns a new instance of Event.



30
31
32
33
34
35
36
37
# File 'lib/periodic-scheduler.rb', line 30

def initialize(quantized_space, now, period, keep, &callback)
			@quantized_space = quantized_space
  @period = period
			@run_time = now + period
  @keep = keep
  @callback = callback
			quantatize(@run_time)
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



28
29
30
# File 'lib/periodic-scheduler.rb', line 28

def callback
  @callback
end

#keepObject (readonly)

Returns the value of attribute keep.



27
28
29
# File 'lib/periodic-scheduler.rb', line 27

def keep
  @keep
end

#periodObject (readonly)

Returns the value of attribute period.



26
27
28
# File 'lib/periodic-scheduler.rb', line 26

def period
  @period
end

#quantum_periodObject (readonly)

Returns the value of attribute quantum_period.



25
26
27
# File 'lib/periodic-scheduler.rb', line 25

def quantum_period
  @quantum_period
end

Instance Method Details

#callObject



71
72
73
# File 'lib/periodic-scheduler.rb', line 71

def call
  @callback.call
end

#keep?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/periodic-scheduler.rb', line 53

def keep?
	@keep
end

#reschedule(qnow) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/periodic-scheduler.rb', line 39

def reschedule(qnow)
	# keep rescheduling until we get it scheduled in future quant
	until @quantum_period > qnow
		@run_time += @period
		quantatize(@run_time)
	end

	@reschedule_hook.call(self) if @reschedule_hook
end

#reschedule_hook(&callback) ⇒ Object



49
50
51
# File 'lib/periodic-scheduler.rb', line 49

def reschedule_hook(&callback)
	@reschedule_hook = callback
end

#stopObject



57
58
59
60
61
# File 'lib/periodic-scheduler.rb', line 57

def stop
	return if @stopped
	@stopped = true
	@stop_hook.call(self) if @reschedule_hook
end

#stop_hook(&callback) ⇒ Object



67
68
69
# File 'lib/periodic-scheduler.rb', line 67

def stop_hook(&callback)
	@stop_hook = callback
end

#stopped?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/periodic-scheduler.rb', line 63

def stopped?
	@stopped
end