@@ -47,16 +47,16 @@ defmodule QuantumStoragePersistentEts do
47
47
48
48
@ doc false
49
49
@ impl Quantum.Storage
50
- def add_job ( storage_pid , job ) , do: GenServer . call ( storage_pid , { :add_job , job } )
50
+ def add_job ( storage_pid , job ) , do: GenServer . cast ( storage_pid , { :add_job , job } )
51
51
52
52
@ doc false
53
53
@ impl Quantum.Storage
54
- def delete_job ( storage_pid , job_name ) , do: GenServer . call ( storage_pid , { :delete_job , job_name } )
54
+ def delete_job ( storage_pid , job_name ) , do: GenServer . cast ( storage_pid , { :delete_job , job_name } )
55
55
56
56
@ doc false
57
57
@ impl Quantum.Storage
58
58
def update_job_state ( storage_pid , job_name , state ) ,
59
- do: GenServer . call ( storage_pid , { :update_job_state , job_name , state } )
59
+ do: GenServer . cast ( storage_pid , { :update_job_state , job_name , state } )
60
60
61
61
@ doc false
62
62
@ impl Quantum.Storage
@@ -65,51 +65,15 @@ defmodule QuantumStoragePersistentEts do
65
65
@ doc false
66
66
@ impl Quantum.Storage
67
67
def update_last_execution_date ( storage_pid , last_execution_date ) ,
68
- do: GenServer . call ( storage_pid , { :update_last_execution_date , last_execution_date } )
68
+ do: GenServer . cast ( storage_pid , { :update_last_execution_date , last_execution_date } )
69
69
70
70
@ doc false
71
71
@ impl Quantum.Storage
72
- def purge ( storage_pid ) , do: GenServer . call ( storage_pid , :purge )
72
+ def purge ( storage_pid ) , do: GenServer . cast ( storage_pid , :purge )
73
73
74
74
@ doc false
75
75
@ impl GenServer
76
- def handle_call ( { :add_job , job } , _from , % State { table: table } = state ) do
77
- { :reply , do_add_job ( table , job ) , state }
78
- end
79
-
80
- def handle_call ( :jobs , _from , % State { table: table } = state ) do
81
- { :reply , do_get_jobs ( table ) , state }
82
- end
83
-
84
- def handle_call ( { :delete_job , job } , _from , % State { table: table } = state ) do
85
- { :reply , do_delete_job ( table , job ) , state }
86
- end
87
-
88
- def handle_call ( { :update_job_state , job_name , job_state } , _from , % State { table: table } = state ) do
89
- { :reply , do_update_job_state ( table , job_name , job_state ) , state }
90
- end
91
-
92
- def handle_call ( :last_execution_date , _from , % State { table: table } = state ) do
93
- { :reply , do_get_last_execution_date ( table ) , state }
94
- end
95
-
96
- def handle_call (
97
- { :update_last_execution_date , last_execution_date } ,
98
- _from ,
99
- % State { table: table } = state
100
- ) do
101
- { :reply , do_update_last_execution_date ( table , last_execution_date ) , state }
102
- end
103
-
104
- def handle_call ( :purge , _from , % State { table: table } = state ) do
105
- { :reply , do_purge ( table ) , state }
106
- end
107
-
108
- defp job_key ( job_name ) do
109
- { :job , job_name }
110
- end
111
-
112
- defp do_add_job ( table , job ) do
76
+ def handle_cast ( { :add_job , job } , % State { table: table } = state ) do
113
77
:ets . insert ( table , entry = { job_key ( job . name ) , job } )
114
78
:ets . insert ( table , { :init_jobs } )
115
79
@@ -119,54 +83,67 @@ defmodule QuantumStoragePersistentEts do
119
83
} ]"
120
84
end )
121
85
122
- :ok
86
+ { :noreply , state }
123
87
end
124
88
125
- defp do_get_jobs ( table ) do
126
- table
127
- |> :ets . lookup ( :init_jobs )
128
- |> case do
129
- [ { :init_jobs } ] ->
130
- table
131
- |> :ets . match ( { { :job , :_ } , :"$1" } )
132
- |> List . flatten ( )
133
-
134
- [ ] ->
135
- :not_applicable
136
- end
137
- end
138
-
139
- defp do_delete_job ( table , job_name ) do
89
+ def handle_cast ( { :delete_job , job_name } , % State { table: table } = state ) do
140
90
:ets . delete ( table , job_key ( job_name ) )
141
91
142
- :ok
92
+ { :noreply , state }
143
93
end
144
94
145
- defp do_update_job_state ( table , job_name , state ) do
95
+ def handle_cast ( { :update_job_state , job_name , job_state } , % State { table: table } = state ) do
146
96
table
147
97
|> :ets . lookup ( job_key ( job_name ) )
148
- |> Enum . map ( & { elem ( & 1 , 0 ) , % { elem ( & 1 , 1 ) | state: state } } )
98
+ |> Enum . map ( & { elem ( & 1 , 0 ) , % { elem ( & 1 , 1 ) | state: job_state } } )
149
99
|> Enum . each ( & :ets . update_element ( table , elem ( & 1 , 0 ) , { 2 , elem ( & 1 , 1 ) } ) )
150
100
151
- :ok
152
- end
153
-
154
- defp do_get_last_execution_date ( table ) do
155
- table
156
- |> :ets . lookup ( :last_execution_date )
157
- |> case do
158
- [ ] -> :unknown
159
- [ { :last_execution_date , date } | _t ] -> date
160
- end
101
+ { :noreply , state }
161
102
end
162
103
163
- defp do_update_last_execution_date ( table , last_execution_date ) do
104
+ def handle_cast (
105
+ { :update_last_execution_date , last_execution_date } ,
106
+ % State { table: table } = state
107
+ ) do
164
108
:ets . insert ( table , { :last_execution_date , last_execution_date } )
165
- :ok
109
+
110
+ { :noreply , state }
166
111
end
167
112
168
- defp do_purge ( table ) do
113
+ def handle_cast ( :purge , % State { table: table } = state ) do
169
114
:ets . delete_all_objects ( table )
170
- :ok
115
+
116
+ { :noreply , state }
117
+ end
118
+
119
+ @ doc false
120
+ @ impl GenServer
121
+ def handle_call ( :jobs , _from , % State { table: table } = state ) do
122
+ { :reply ,
123
+ table
124
+ |> :ets . lookup ( :init_jobs )
125
+ |> case do
126
+ [ { :init_jobs } ] ->
127
+ table
128
+ |> :ets . match ( { { :job , :_ } , :"$1" } )
129
+ |> List . flatten ( )
130
+
131
+ [ ] ->
132
+ :not_applicable
133
+ end , state }
134
+ end
135
+
136
+ def handle_call ( :last_execution_date , _from , % State { table: table } = state ) do
137
+ { :reply ,
138
+ table
139
+ |> :ets . lookup ( :last_execution_date )
140
+ |> case do
141
+ [ ] -> :unknown
142
+ [ { :last_execution_date , date } | _t ] -> date
143
+ end , state }
144
+ end
145
+
146
+ defp job_key ( job_name ) do
147
+ { :job , job_name }
171
148
end
172
149
end
0 commit comments