-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHistoricTimer.jl
59 lines (52 loc) · 1.65 KB
/
HistoricTimer.jl
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
mutable struct HistoricTimer{TPeriod,TTime,TAdapterFunc} <: SourceAdapter
node::StreamNode
adapter_func::TAdapterFunc
interval::TPeriod
current_time::TTime
function HistoricTimer{TTime}(
executor,
node::StreamNode
;
interval::TPeriod,
start_time::TTime
) where {TPeriod,TTime}
adapter_func = executor.adapter_funcs[node.index]
new{TPeriod,TTime,typeof(adapter_func)}(node, adapter_func, interval, start_time)
end
end
function setup!(
adapter::HistoricTimer{TPeriod,TTime},
executor::HistoricExecutor{TStates,TTime}
) where {TPeriod,TStates,TTime}
# Initialize current time of the timer
if adapter.current_time < start_time(executor)
adapter.current_time = start_time(executor)
end
if adapter.current_time > end_time(executor)
return
end
# Schedule first event
push!(executor.event_queue, ExecutionEvent(adapter.current_time, adapter))
nothing
end
function process_event!(
adapter::HistoricTimer{TPeriod,TTime},
executor::HistoricExecutor{TStates,TTime},
event::ExecutionEvent{TTime}
) where {TPeriod,TStates,TTime}
# Execute subgraph based on current value
adapter.adapter_func(executor, adapter.current_time)
nothing
end
function advance!(
adapter::HistoricTimer{TPeriod,TTime},
executor::HistoricExecutor{TStates,TTime}
) where {TPeriod,TStates,TTime}
# Schedule next event
adapter.current_time += adapter.interval
if adapter.current_time <= end_time(executor)
event = ExecutionEvent(adapter.current_time, adapter)
push!(executor.event_queue, event)
end
nothing
end