-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdb_worker.ex
More file actions
31 lines (25 loc) · 617 Bytes
/
Copy pathdb_worker.ex
File metadata and controls
31 lines (25 loc) · 617 Bytes
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
defmodule Csv2sql.DbWorker do
use GenServer
alias Csv2sql.{JobQueueServer, Database}
def start_link(_) do
GenServer.start_link(__MODULE__, :no_args)
end
def init(_) do
Process.send_after(self(), :start_new_db_work, 0)
{:ok, nil}
end
@doc """
Recursively requests the job queue for work(chunks of data)
"""
def handle_info(:start_new_db_work, _) do
JobQueueServer.get_work()
|> case do
{file, data_chunk} ->
Database.insert_data_chunk(file, data_chunk)
:no_work ->
nil
end
send(self(), :start_new_db_work)
{:noreply, nil}
end
end