Skip to content

Commit dd810c6

Browse files
Arpan-KreetiArp-G
authored andcommitted
Timer server fixes
1 parent 751ebb7 commit dd810c6

File tree

3 files changed

+30
-52
lines changed

3 files changed

+30
-52
lines changed

apps/csv2sql/lib/csv2sql/application.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ defmodule Csv2sql.Application do
1414
end
1515

1616
children =
17-
[
18-
{Csv2sql.TimerServer, Time.utc_now()}
19-
]
17+
[]
2018
|> Kernel.++(repo_supervisor)
2119
|> Kernel.++([
2220
Csv2sql.FileServer,

apps/csv2sql/lib/csv2sql/main_server.ex

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ defmodule Csv2sql.MainServer do
1010
GenServer.cast(__MODULE__, :done)
1111
end
1212

13-
def get_worker_count() do
14-
GenServer.call(__MODULE__, :get_active_worker_count)
15-
end
16-
1713
# Starts the server with initial state set to worker_count
1814
# The init function uses send_after to tell the runtime to queue a message to this
1915
# server immediately (that is, after waiting 0 ms). When the init function exits, the
@@ -50,16 +46,14 @@ defmodule Csv2sql.MainServer do
5046
{:noreply, worker_count}
5147
end
5248

53-
def handle_call(:get_active_worker_count, _from, worker_count) do
54-
{:reply, worker_count, worker_count}
55-
end
56-
5749
def handle_cast(:done, 1) do
50+
Csv2sql.Observer.update_active_worker_count(0)
51+
5852
set_validate = Application.get_env(:csv2sql, Csv2sql.MainServer)[:set_validate]
5953

6054
wait_for_pending_jobs()
6155

62-
:timer.sleep(2000)
56+
:timer.sleep(500)
6357

6458
start_validation_message()
6559

@@ -76,7 +70,7 @@ defmodule Csv2sql.MainServer do
7670
Csv2sql.Helpers.print_msg("\nValidation Process Skipped...\n\n", :green)
7771
end
7872

79-
Csv2sql.TimerServer.get_time_spend()
73+
pretty_print_time_take()
8074

8175
:timer.sleep(100)
8276

@@ -86,6 +80,7 @@ defmodule Csv2sql.MainServer do
8680
end
8781

8882
def handle_cast(:done, worker_count) do
83+
Csv2sql.Observer.update_active_worker_count(worker_count - 1)
8984
{:noreply, worker_count - 1}
9085
end
9186

@@ -96,6 +91,30 @@ defmodule Csv2sql.MainServer do
9691
end
9792
end
9893

94+
defp pretty_print_time_take() do
95+
%{start_time: start_time} = Csv2sql.Observer.get_stats()
96+
97+
time_taken =
98+
DateTime.utc_now()
99+
|> Time.diff(start_time, :millisecond)
100+
|> Kernel./(1000)
101+
|> Float.round()
102+
103+
"""
104+
105+
----------------------------------------
106+
107+
FINISHED !!!
108+
109+
The operation took #{time_taken} seconds
110+
111+
112+
----------------------------------------
113+
114+
"""
115+
|> Csv2sql.Helpers.print_msg(:green)
116+
end
117+
99118
defp make_directories_if_not_present() do
100119
source_csv_directory =
101120
Application.get_env(:csv2sql, Csv2sql.MainServer)[:source_csv_directory]

apps/csv2sql/lib/csv2sql/timer_server.ex

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)