Skip to content

Commit fc58be7

Browse files
committed
Merge branch 'feature/utc_datetimes'
2 parents d9e3ab6 + 8f6da84 commit fc58be7

File tree

8 files changed

+72
-52
lines changed

8 files changed

+72
-52
lines changed

README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,36 @@ Note: You should read [how to install honeydew here first](https://github.com/ko
7373
This queue takes some additional options. An example below,
7474

7575
```elixir
76-
import Supervisor.Spec
77-
7876
def background_job_processes do
7977
[
8078
notifier_process(),
81-
Honeydew.queue_spec(:process, # queue_name
82-
queue: {HoneydewEctoNotifyQueue, [
83-
repo: YourApp.Repo, # your app's Repo module
84-
max_job_time: 3_600, # seconds
85-
retry_seconds: 15, # seconds,
86-
notifier: YourApp.Notifier # this should match the `name:` in `notifier_process` below
87-
]},
88-
failure_mode: {Honeydew.FailureMode.Retry, times: 3}
89-
),
90-
Honeydew.worker_spec(:process, YourApp.Worker, num: 1)
79+
{
80+
Honeydew.Queues,
81+
[
82+
:process, # queue name
83+
queue: {
84+
HoneydewEctoNotifyQueue, [
85+
repo: YourApp.Repo,
86+
max_job_time: 3_600, # seconds
87+
retry_seconds: 15, # seconds,
88+
notifier: YourApp.Notifier # this should match the `name` in `notifier_process` below
89+
]
90+
},
91+
failure_mode: {Honeydew.FailureMode.Retry, times: 3}
92+
]
93+
},
94+
{
95+
Honeydew.Workers,
96+
[:process, YourApp.Workers.ProcessWorker, num: 1]
97+
}
9198
]
9299
end
93100

94101
def notifier_process do
95-
worker(Postgrex.Notifications, [YourApp.Repo.config() ++ [name: YourApp.Notifier]])
102+
%{
103+
id: Postgrex.Notifications,
104+
start: {Postgrex.Notifications, :start_link, [YourApp.Repo.config() ++ [name: YourApp.Notifier]]}
105+
}
96106
end
97107

98108
def start(_type, _args) do

lib/honeydew_ecto_notify_queue/config.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ defmodule HoneydewEctoNotifyQueue.Config do
5555
iex> update_config(Repo, "queueing_mode", "manual")
5656
{:ok, %JobConfig{}}
5757
"""
58-
@spec update_config(Repo.t(), JobConfig.t() | String.t(), String.t()) :: {:ok, JobConfig.t()} | {:error, any}
58+
@spec update_config(Repo.t(), JobConfig.t() | String.t(), String.t()) ::
59+
{:ok, JobConfig.t()} | {:error, any}
5960
def update_config(repo, %JobConfig{} = config, value) when is_binary(value) do
6061
config
6162
|> JobConfig.changeset(%{value: value})

lib/honeydew_ecto_notify_queue/jobs/job.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ defmodule HoneydewEctoNotifyQueue.Job do
1010
field :function, :string
1111
field :arguments, :map
1212
field :failure_state, :map
13-
field :reserved_at, :naive_datetime
14-
field :acked_at, :naive_datetime
15-
field :abandoned_at, :naive_datetime
16-
field :nacked_until, :naive_datetime
13+
field :reserved_at, :utc_datetime_usec
14+
field :acked_at, :utc_datetime_usec
15+
field :abandoned_at, :utc_datetime_usec
16+
field :nacked_until, :utc_datetime_usec
1717

18-
timestamps()
18+
timestamps(type: :utc_datetime_usec)
1919
end
2020

2121
def changeset(%__MODULE__{} = job, attrs) do

lib/honeydew_ecto_notify_queue/jobs/job_config.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ defmodule HoneydewEctoNotifyQueue.JobConfig do
88

99
@primary_key {:id, :binary_id, autogenerate: true}
1010
schema "job_configs" do
11-
field(:key, :string)
12-
field(:value, :string)
11+
field :key, :string
12+
field :value, :string
1313

14-
timestamps()
14+
timestamps(type: :utc_datetime_usec)
1515
end
1616

1717
def changeset(%__MODULE__{} = config, attrs) do

mix.exs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,26 @@ defmodule HoneydewEctoNotifyQueue.MixProject do
3838
{:postgrex, "~> 0.14"},
3939
{:poison, "~> 3.1"},
4040
{:honeydew, "~> 1.1.5"},
41-
{:jason, "~> 1.1"},
41+
{:jason, "~> 1.1"}
4242
]
4343
end
4444

4545
defp package do
46-
[maintainers: ["Andrew Pett"],
47-
licenses: ["MIT"],
48-
links: %{"GitHub": "https://github.com/aspett/honeydew-ecto-notify-queue"}]
46+
[
47+
maintainers: ["Andrew Pett"],
48+
licenses: ["MIT"],
49+
links: %{GitHub: "https://github.com/aspett/honeydew-ecto-notify-queue"}
50+
]
4951
end
5052

5153
defp docs do
52-
[extras: ["README.md"],
53-
source_url: "https://github.com/aspett/honeydew-ecto-notify-queue",
54-
assets: "assets",
55-
main: "readme",
56-
source_ref: @version]
54+
[
55+
extras: ["README.md"],
56+
source_url: "https://github.com/aspett/honeydew-ecto-notify-queue",
57+
assets: "assets",
58+
main: "readme",
59+
source_ref: @version
60+
]
5761
end
5862

5963
defp aliases do

priv/repo/migrations/20180702161041_honeydew_ecto_notify_jobs.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ defmodule HoneydewEctoNotifyQueue.Repo.Migrations.CreateHoneydewEctoNotifyTables
88
add :function, :string
99
add :arguments, :jsonb
1010
add :failure_state, :jsonb
11-
add :reserved_at, :naive_datetime
12-
add :nacked_until, :naive_datetime
13-
add :acked_at, :naive_datetime
14-
add :abandoned_at, :naive_datetime
11+
add :reserved_at, :utc_datetime_usec
12+
add :nacked_until, :utc_datetime_usec
13+
add :acked_at, :utc_datetime_usec
14+
add :abandoned_at, :utc_datetime_usec
1515

1616
timestamps()
1717
end

priv/templates/migration.exs.eex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ defmodule <%= module_prefix %>.Repo.Migrations.CreateHoneydewEctoNotifyTables do
88
add :function, :string
99
add :arguments, :jsonb
1010
add :failure_state, :jsonb
11-
add :reserved_at, :naive_datetime
12-
add :nacked_until, :naive_datetime
13-
add :acked_at, :naive_datetime
14-
add :abandoned_at, :naive_datetime
11+
add :reserved_at, :utc_datetime_usec
12+
add :nacked_until, :utc_datetime_usec
13+
add :acked_at, :utc_datetime_usec
14+
add :abandoned_at, :utc_datetime_usec
1515

16-
timestamps()
16+
timestamps(type: :utc_datetime_usec)
1717
end
1818

1919
create index(:jobs, [:reserved_at, :acked_at, :nacked_until], using: :btree)
@@ -25,7 +25,7 @@ defmodule <%= module_prefix %>.Repo.Migrations.CreateHoneydewEctoNotifyTables do
2525
add :key, :string, null: false
2626
add :value, :string, null: false
2727

28-
timestamps()
28+
timestamps(type: :utc_datetime_usec)
2929
end
3030

3131
create unique_index(:job_configs, [:key], using: :btree)

test/honeydew_ecto_notify_queue_integration_test.exs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,22 @@ defmodule HoneydewEctoNotifyQueueIntegrationTest do
3434
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Repo)
3535
Ecto.Adapters.SQL.Sandbox.mode(Repo, {:shared, self()})
3636

37-
queue = :"#{:erlang.monotonic_time}_#{:erlang.unique_integer}"
38-
39-
spec = Honeydew.queue_spec(queue,
40-
queue: {HoneydewEctoNotifyQueue, [
41-
repo: HoneydewEctoNotifyQueue.Repo,
42-
max_job_time: 3_600, # seconds
43-
retry_seconds: 15, # seconds,
44-
notifier: Notifier
45-
]},
46-
failure_mode: {Honeydew.FailureMode.Retry, times: 3}
47-
)
37+
queue = :"#{:erlang.monotonic_time()}_#{:erlang.unique_integer()}"
38+
39+
spec =
40+
Honeydew.queue_spec(queue,
41+
queue:
42+
{HoneydewEctoNotifyQueue,
43+
[
44+
repo: HoneydewEctoNotifyQueue.Repo,
45+
# seconds
46+
max_job_time: 3_600,
47+
# seconds,
48+
retry_seconds: 15,
49+
notifier: Notifier
50+
]},
51+
failure_mode: {Honeydew.FailureMode.Retry, times: 3}
52+
)
4853

4954
{_queue, {queue_module, startfn, args}, restart, timeout, type, _module} = spec
5055

0 commit comments

Comments
 (0)