@@ -9,6 +9,38 @@ defmodule EctoWatch do
9
9
10
10
use Supervisor
11
11
12
+ def start_link ( opts ) do
13
+ case EctoWatch.Options . validate ( opts ) do
14
+ { :ok , validated_opts } ->
15
+ options = EctoWatch.Options . new ( validated_opts )
16
+
17
+ validate_watcher_uniqueness ( options . watchers )
18
+
19
+ Supervisor . start_link ( __MODULE__ , options , name: __MODULE__ )
20
+
21
+ { :error , errors } ->
22
+ raise ArgumentError , "Invalid options: #{ Exception . message ( errors ) } "
23
+ end
24
+ end
25
+
26
+ def init ( options ) do
27
+ # TODO:
28
+ # Allow passing in options specific to Postgrex.Notifications.start_link/1
29
+ # https://hexdocs.pm/postgrex/Postgrex.Notifications.html#start_link/1
30
+
31
+ postgrex_notifications_options =
32
+ options . repo_mod . config ( )
33
+ |> Keyword . put ( :name , :ecto_watch_postgrex_notifications )
34
+
35
+ children = [
36
+ { Postgrex.Notifications , postgrex_notifications_options } ,
37
+ { EctoWatch.WatcherSupervisor , options } ,
38
+ { WatcherTriggerValidator , nil }
39
+ ]
40
+
41
+ Supervisor . init ( children , strategy: :rest_for_one )
42
+ end
43
+
12
44
@ since "0.8.0"
13
45
@ deprecated "subscribe/3 was removed in version 0.8.0. See the updated documentation"
14
46
def subscribe ( schema_mod_or_label , update_type , id ) when is_atom ( schema_mod_or_label ) do
@@ -220,38 +252,6 @@ defmodule EctoWatch do
220
252
end
221
253
end
222
254
223
- def start_link ( opts ) do
224
- case EctoWatch.Options . validate ( opts ) do
225
- { :ok , validated_opts } ->
226
- options = EctoWatch.Options . new ( validated_opts )
227
-
228
- validate_watcher_uniqueness ( options . watchers )
229
-
230
- Supervisor . start_link ( __MODULE__ , options , name: __MODULE__ )
231
-
232
- { :error , errors } ->
233
- raise ArgumentError , "Invalid options: #{ Exception . message ( errors ) } "
234
- end
235
- end
236
-
237
- def init ( options ) do
238
- # TODO:
239
- # Allow passing in options specific to Postgrex.Notifications.start_link/1
240
- # https://hexdocs.pm/postgrex/Postgrex.Notifications.html#start_link/1
241
-
242
- postgrex_notifications_options =
243
- options . repo_mod . config ( )
244
- |> Keyword . put ( :name , :ecto_watch_postgrex_notifications )
245
-
246
- children = [
247
- { Postgrex.Notifications , postgrex_notifications_options } ,
248
- { EctoWatch.WatcherSupervisor , options } ,
249
- { WatcherTriggerValidator , nil }
250
- ]
251
-
252
- Supervisor . init ( children , strategy: :rest_for_one )
253
- end
254
-
255
255
defp validate_watcher_uniqueness ( watcher_options ) do
256
256
{ without_labels , with_labels } = Enum . split_with ( watcher_options , & ( & 1 . label == nil ) )
257
257
0 commit comments