Skip to content

Commit

Permalink
Upgrade Timex to 2.1.4
Browse files Browse the repository at this point in the history

Tzdata application needs to be started in tests otherwise it fails with
ArgumentError when trying to do :ets.lookup(:tzdata_current_release,
:release_version).

* Use :seconds instead of :secs to avoid Timex warning.

* Ensure Tzdata app started in test_helper.exs.
  • Loading branch information
krasio authored and edgurgel committed Apr 4, 2016
1 parent f39bbd8 commit af9ecfa
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 19 deletions.
1 change: 1 addition & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ config :logger, :console,

if Mix.env == :test do
config :logger, backends: [] # Silent logging for tests
config :tzdata, :autoupdate, :disabled
config :verk, queues: [{:default, 1}], redis_url: "redis://127.0.0.1:6379/1"
end

2 changes: 1 addition & 1 deletion lib/verk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ defmodule Verk do
def schedule(%Job{ jid: jid } = job, %DateTime{} = perform_at, redis) do
perform_at_secs = Date.to_secs(perform_at)

if perform_at_secs < Time.now(:secs) do
if perform_at_secs < Time.now(:seconds) do
enqueue(job, redis)
else
case Redix.command(redis, ["ZADD", @schedule_key, perform_at_secs, Poison.encode!(job)]) do
Expand Down
2 changes: 1 addition & 1 deletion lib/verk/log.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ defmodule Verk.Log do
end

defp elapsed(start_time) do
start_time |> Date.diff(Date.now, :secs)
start_time |> Date.diff(Date.now, :seconds)
end
end
2 changes: 1 addition & 1 deletion lib/verk/queue_manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ defmodule Verk.QueueManager do
"""
def retry(queue_manager, job, exception, stacktrace, timeout \\ 5000) do
try do
GenServer.call(queue_manager, { :retry, job, Timex.Time.now(:secs), exception, stacktrace }, timeout)
GenServer.call(queue_manager, { :retry, job, Timex.Time.now(:seconds), exception, stacktrace }, timeout)
catch
:exit, { :timeout, _ } -> :timeout
end
Expand Down
2 changes: 1 addition & 1 deletion lib/verk/schedule_manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule Verk.ScheduleManager do
end

defp handle_info(fetch_message, state, queue) do
case Redix.command(state.redis, ["EVALSHA", @enqueue_retriable_script_sha, 1, queue, Time.now(:secs)]) do
case Redix.command(state.redis, ["EVALSHA", @enqueue_retriable_script_sha, 1, queue, Time.now(:seconds)]) do
{ :ok, nil } ->
schedule_fetch!(fetch_message)
{ :noreply, state }
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule Verk.Mixfile do
defp deps do
[{ :redix, "~> 0.3" },
{ :poison, "~> 1.5" },
{ :timex, "~> 1.0" },
{ :timex, "~> 2.0" },
{ :poolboy, "~> 1.5.1" },
{ :watcher, "~> 1.0" },
{ :earmark, "~> 0.1.17", only: :docs },
Expand Down
9 changes: 5 additions & 4 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
"coverex": {:hex, :coverex, "1.4.8"},
"earmark": {:hex, :earmark, "0.1.19"},
"ex_doc": {:hex, :ex_doc, "0.8.4"},
"hackney": {:hex, :hackney, "1.4.8"},
"gettext": {:hex, :gettext, "0.10.0"},
"hackney": {:hex, :hackney, "1.4.10"},
"httpoison": {:hex, :httpoison, "0.8.1"},
"idna": {:hex, :idna, "1.0.3"},
"idna": {:hex, :idna, "1.1.0"},
"meck": {:hex, :meck, "0.8.4"},
"mimerl": {:hex, :mimerl, "1.0.2"},
"poison": {:hex, :poison, "1.5.2"},
"poolboy": {:hex, :poolboy, "1.5.1"},
"redix": {:hex, :redix, "0.3.4"},
"ssl_verify_hostname": {:hex, :ssl_verify_hostname, "1.0.5"},
"timex": {:hex, :timex, "1.0.0"},
"tzdata": {:hex, :tzdata, "0.5.6"},
"timex": {:hex, :timex, "2.1.4"},
"tzdata": {:hex, :tzdata, "0.5.7"},
"watcher": {:hex, :watcher, "1.0.0"}}
12 changes: 6 additions & 6 deletions test/schedule_manager_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule Verk.ScheduleManagerTest do
test "handle_info :fetch_retryable without jobs to retry", %{ script: script } do
state = %State{ redis: :redis }
now = :now
expect(Timex.Time, :now, [:secs], now)
expect(Timex.Time, :now, [:seconds], now)
expect(Redix, :command, [:redis, ["EVALSHA", script, 1, "retry", now]], {:ok, nil})

assert handle_info(:fetch_retryable, state) == { :noreply, state }
Expand All @@ -41,7 +41,7 @@ defmodule Verk.ScheduleManagerTest do
state = %State{ redis: :redis }
now = :now
encoded_job = "encoded_job"
expect(Timex.Time, :now, [:secs], now)
expect(Timex.Time, :now, [:seconds], now)
expect(Redix, :command, [:redis, ["EVALSHA", script, 1, "retry", now]], {:ok, encoded_job})

assert handle_info(:fetch_retryable, state) == { :noreply, state }
Expand All @@ -53,7 +53,7 @@ defmodule Verk.ScheduleManagerTest do
test "handle_info :fetch_retryable with jobs to retry and redis failed to apply the script", %{ script: script } do
state = %State{ redis: :redis }
now = :now
expect(Timex.Time, :now, [:secs], now)
expect(Timex.Time, :now, [:seconds], now)
expect(Redix, :command, [:redis, ["EVALSHA", script, 1, "retry", now]], {:error, %Redix.Error{message: "a message"}})

assert handle_info(:fetch_retryable, state) == { :stop, :redis_failed, state }
Expand All @@ -64,7 +64,7 @@ defmodule Verk.ScheduleManagerTest do
test "handle_info :fetch_scheduled without jobs to run", %{ script: script } do
state = %State{ redis: :redis }
now = :now
expect(Timex.Time, :now, [:secs], now)
expect(Timex.Time, :now, [:seconds], now)
expect(Redix, :command, [:redis, ["EVALSHA", script, 1, "schedule", now]], {:ok, nil})

assert handle_info(:fetch_scheduled, state) == { :noreply, state }
Expand All @@ -77,7 +77,7 @@ defmodule Verk.ScheduleManagerTest do
state = %State{ redis: :redis }
now = :now
encoded_job = "encoded_job"
expect(Timex.Time, :now, [:secs], now)
expect(Timex.Time, :now, [:seconds], now)
expect(Redix, :command, [:redis, ["EVALSHA", script, 1, "schedule", now]], {:ok, encoded_job})

assert handle_info(:fetch_scheduled, state) == { :noreply, state }
Expand All @@ -89,7 +89,7 @@ defmodule Verk.ScheduleManagerTest do
test "handle_info :fetch_scheduled with jobs to run and redis failed to apply the script", %{ script: script } do
state = %State{ redis: :redis }
now = :now
expect(Timex.Time, :now, [:secs], now)
expect(Timex.Time, :now, [:seconds], now)
expect(Redix, :command, [:redis, ["EVALSHA", script, 1, "schedule", now]], {:error, %Redix.Error{message: "a message"}})

assert handle_info(:fetch_scheduled, state) == { :stop, :redis_failed, state }
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ExUnit.start()
{ :ok, _ } = Application.ensure_all_started(:tzdata)
8 changes: 4 additions & 4 deletions test/verk_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ defmodule VerkTest do
end

test "schedule a job with a jid, a queue and a perform_in" do
now = Timex.Date.now
perform_at = Timex.Date.shift(now, days: 1)
now = Timex.DateTime.now
perform_at = Timex.DateTime.shift(now, days: 1)
job = %Verk.Job{ queue: "test_queue", jid: "job_id", class: "TestWorker", args: [] }
encoded_job = "encoded_job"
expect(Poison, :encode!, [job], encoded_job)
Expand All @@ -129,8 +129,8 @@ defmodule VerkTest do
end

test "schedule a job with a jid, a queue and a perform_in passing a redis connection" do
now = Timex.Date.now
perform_at = Timex.Date.shift(now, days: 1)
now = Timex.DateTime.now
perform_at = Timex.DateTime.shift(now, days: 1)
job = %Verk.Job{ queue: "test_queue", jid: "job_id", class: "TestWorker", args: [] }
encoded_job = "encoded_job"
expect(Poison, :encode!, [job], encoded_job)
Expand Down

0 comments on commit af9ecfa

Please sign in to comment.