put the pid in the state, reuse the handle etcetcetc

e0601e2 · gmorell · 2023-07-28 04:47

5 files +7 -4

Files changed

modified apps/room_gtfs/lib/room_gtfs/gtfs_worker.ex
+7 −4
@@ -126,12 +126,15 @@ defmodule RoomGtfs.Worker do
126 126 {:ok, child_rt} = Parent.start_child({RoomGtfs.Worker.RT, opts})
127 127 {:ok, child_static} = Parent.start_child({RoomGtfs.Worker.Static, opts})
128 128
129 + {:ok, pid} = Postgrex.start_link(opts)
130 +
129 131 {:ok,
130 132 %{
131 133 id: opts[:name],
132 134 inst: nil,
133 135 child_rt: child_rt,
134 − child_static: child_static
136 + child_static: child_static,
137 + pg_pid: pid,
135 138 }}
136 139 end
137 140
@@ -470,7 +473,7 @@ defmodule RoomGtfs.Worker.Static do
470 473 |> Enum.join(", ")
471 474 end
472 475
473 − defp write_file(contents, type, id, via: :copy) do
476 + defp write_file(contents, type, id, via: :copy, pid) do
474 477 datetime = NaiveDateTime.local_now()
475 478 Logger.info("GTFS::#{id} writing #{type} (c)")
476 479
@@ -517,7 +520,7 @@ end
517 520
518 521 # IO.inspect({table, columns, pg_cols})
519 522 opts = RoomSanctum.Repo.config()
520 − {:ok, pid} = Postgrex.start_link(opts)
523 +# {:ok, pid} = Postgrex.start_link(opts)
521 524
522 525 tmp_table_name = "tmp_#{type}_#{id}"
523 526
@@ -781,7 +784,7 @@ end
781 784 bcast(state.id, file_to_atom(e.file_name), file_to_order(e.file_name), 9)
782 785
783 786 Unzip.file_stream!(unzip, e.file_name)
784 − |> write_file(file_to_atom(e.file_name), state.id, via: :copy)
787 + |> write_file(file_to_atom(e.file_name), state.id, via: :copy, state.pg_pid)
785 788
786 789 # bcast(state.id, :stop_times, 8, 9)
787 790 end

Parents: 8dab11d