Skip to content

Commit

Permalink
refactor: Improve package documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rai200890 committed Jul 1, 2019
1 parent 56b6591 commit 233e312
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 27 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# EctoJobScheduler

[![CircleCI](https://circleci.com/gh/rai200890/ecto-job-scheduler/tree/master.svg?style=svg)](https://circleci.com/gh/rai200890/ecto-job-scheduler/tree/master)
![Hex.pm](https://img.shields.io/hexpm/v/ecto_job_scheduler.svg)
![Hex.pm](https://img.shields.io/hexpm/l/ecto_job_scheduler.svg)

Helpers for scheduling Jobs defined in [EctoJob](https://github.com/mbuhot/ecto_job)

Thanks [joaothallis](https://github.com/joaothallis), [ramondelemos](https://github.com/ramondelemos), [victorprs](https://github.com/victorprs)

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
Expand All @@ -12,7 +16,7 @@ by adding `ecto_job_scheduler` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:ecto_job_scheduler, "~> 0.1.0"}
{:ecto_job_scheduler, "~> 0.2.0"}
]
end
```
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.2.0
4 changes: 3 additions & 1 deletion lib/job.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
defmodule EctoJobScheduler.Job do
@moduledoc false
@moduledoc """
Defines jobs to be used with EctoJobScheduler.JobQueue and EctoJobScheduler.JobScheduler
"""
alias Ecto.Multi
alias EctoJobScheduler.JobInfo

Expand Down
13 changes: 11 additions & 2 deletions lib/job_info.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
defmodule EctoJobScheduler.JobInfo do
@moduledoc false

@moduledoc """
Metadata about EctoJob
"""
alias Ecto.{Changeset, Multi}

defstruct [:multi, :job_queue, :attempt, :max_attempts]

@type t :: %__MODULE__{
multi: Ecto.Multi.t(),
job_queue: any(),
attempt: integer(),
max_attempts: integer()
}

@spec new(Ecto.Multi.t()) :: __MODULE__.t()
def new(multi) do
case multi |> Multi.to_list() |> List.first() do
{_job_name, {:delete, %Changeset{data: job_queue}, _options}} ->
Expand Down
4 changes: 3 additions & 1 deletion lib/job_queue.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
defmodule EctoJobScheduler.JobQueue do
@moduledoc false
@moduledoc """
Defines EctoJob.JobQueue based on defined EctoJobScheduler.Job
"""

defmacro __using__(table_name: table_name, jobs: jobs) do
quote bind_quoted: [table_name: table_name, jobs: jobs] do
Expand Down
5 changes: 4 additions & 1 deletion lib/job_scheduler.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
defmodule EctoJobScheduler.JobScheduler do
@moduledoc false
@moduledoc """
Defines scheduler for multiple EctoJobScheduler.Job
"""

alias Ecto.Multi
alias EctoJobScheduler.Logger.Context

Expand Down
9 changes: 7 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ defmodule EctoJobScheduler.MixProject do
],
description: description(),
package: package(),
source_url: "https://github.com/rai200890/ecto-job-scheduler"
source_url: "https://github.com/rai200890/ecto-job-scheduler",
docs: [
main: "readme",
extras: ["README.md"]
]
]
end

Expand Down Expand Up @@ -50,7 +54,8 @@ defmodule EctoJobScheduler.MixProject do
{:ecto_job, "~> 2.1"},
{:credo, "~> 1.1", only: [:dev, :test], runtime: false},
{:excoveralls, "~> 0.10", only: :test},
{:ex_doc, "~> 0.14", only: :dev, runtime: false}
{:ex_doc, "~> 0.14", only: :dev, runtime: false},
{:dialyxir, "~> 0.5", only: [:dev], runtime: false}
]
end
end
5 changes: 3 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"credo": {:hex, :credo, "1.1.0", "e0c07b2fd7e2109495f582430a1bc96b2c71b7d94c59dfad120529f65f19872f", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"db_connection": {:hex, :db_connection, "2.1.0", "122e2f62c4906bf2e49554f1e64db5030c19229aa40935f33088e7d543aa79d0", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
"decimal": {:hex, :decimal, "1.8.0", "ca462e0d885f09a1c5a342dbd7c1dcf27ea63548c65a65e67334f4b61803822e", [:mix], [], "hexpm"},
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm"},
"earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"},
"ecto": {:hex, :ecto, "3.1.6", "e890bf66c1d4d8e2b8e010f7cba092a08139b55437bc3382371f72a6ee40757e", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"ecto": {:hex, :ecto, "3.1.7", "fa21d06ef56cdc2fdaa62574e8c3ba34a2751d44ea34c30bc65f0728421043e5", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"ecto_job": {:hex, :ecto_job, "2.1.0", "aa8af215011af367ad13712a9a4d2dbd2df8c696bf13241ed807ca2565e72716", [:mix], [{:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:gen_stage, "~> 0.13", [hex: :gen_stage, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.14", [hex: :postgrex, repo: "hexpm", optional: false]}], "hexpm"},
"ecto_sql": {:hex, :ecto_sql, "3.1.5", "b5201fe99fa6bf6a93f64adb2d4976ded3d201f932b7c5bd4c44468642f4fb1f", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.1.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:myxql, "~> 0.2.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0 or ~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
"ecto_sql": {:hex, :ecto_sql, "3.1.6", "1e80e30d16138a729c717f73dcb938590bcdb3a4502f3012414d0cbb261045d8", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.1.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:myxql, "~> 0.2.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0 or ~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"excoveralls": {:hex, :excoveralls, "0.11.1", "dd677fbdd49114fdbdbf445540ec735808250d56b011077798316505064edb2c", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"gen_stage": {:hex, :gen_stage, "0.14.2", "6a2a578a510c5bfca8a45e6b27552f613b41cf584b58210f017088d3d17d0b14", [:mix], [], "hexpm"},
Expand Down
13 changes: 1 addition & 12 deletions test/support/data_case.ex
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
defmodule EctoJobScheduler.DataBase do
@moduledoc """
This module defines the setup for tests requiring
access to the application's data layer.
You may define functions here to be used as helpers in
your tests.
Finally, if the test case interacts with the database,
it cannot be async. For this reason, every test runs
inside a transaction which is reset at the beginning
of the test unless the test case is marked as async.
"""
@moduledoc false

use ExUnit.CaseTemplate
alias Ecto.Adapters.SQL.Sandbox
Expand Down
4 changes: 0 additions & 4 deletions test/support/helpers/ecto_job_helpers.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
defmodule EctoJobScheduler.Support.Helpers.EctoJobHelpers do
@moduledoc false
alias EctoJobScheduler.JobQueue
alias EctoJobScheduler.Test.Repo

import ExUnit.Assertions
Expand All @@ -11,7 +10,6 @@ defmodule EctoJobScheduler.Support.Helpers.EctoJobHelpers do
max_attempts: 5
]

@spec build_initial_multi(JobQueue.t(), map(), keyword()) :: Ecto.Multi.t()
def build_initial_multi(job_queue, job_args, options \\ []) do
merged_options = Keyword.merge(@default_options, options)
job = job_queue.new(job_args, max_attempts: Keyword.get(merged_options, :max_attempts))
Expand All @@ -20,14 +18,12 @@ defmodule EctoJobScheduler.Support.Helpers.EctoJobHelpers do
initial_multi(job)
end

@spec dispatch_job(JobQueue.t(), JobQueue.t()) :: list({:ok, any()} | {:error, any()})
def dispatch_job(job_queue, job) do
result = job |> initial_multi() |> job_queue.perform(job.params)
update_job!(job_queue, job)
result
end

@spec assert_job_executed_successfully(JobQueue.t(), JobQueue.t()) :: boolean()
def assert_job_executed_successfully(job_queue, job) do
job |> initial_multi() |> job_queue.perform(job.params)
assert job_queue |> Repo.get(job.id) |> is_nil()
Expand Down
1 change: 1 addition & 0 deletions test/support/repo.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
defmodule EctoJobScheduler.Test.Repo do
@moduledoc false
use Ecto.Repo, otp_app: :ecto_job_scheduler, adapter: Ecto.Adapters.Postgres
end

0 comments on commit 233e312

Please sign in to comment.