-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0e2e64
commit 02dcd29
Showing
16 changed files
with
346 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
defmodule Sanbase.Metric.Registry.SyncSchema do | ||
use Ecto.Schema | ||
|
||
import Ecto.Query | ||
import Ecto.Changeset | ||
|
||
schema "metric_registry_syncs" do | ||
field(:uuid, :string) | ||
field(:status, :string) | ||
field(:content, :string) | ||
field(:errors, :string) | ||
|
||
timestamps() | ||
end | ||
|
||
def changeset(%__MODULE__{} = sync, attrs) do | ||
sync | ||
|> cast(attrs, [:uuid, :content, :status, :errors]) | ||
|> validate_inclusion(:status, ["scheduled", "executing", "completed", "failed"]) | ||
end | ||
|
||
def create(content) do | ||
%__MODULE__{} | ||
|> changeset(%{content: content, status: "scheduled", uuid: Ecto.UUID.generate()}) | ||
|> Sanbase.Repo.insert() | ||
end | ||
|
||
def update_status(%__MODULE__{} = struct, status, errors \\ nil) do | ||
struct | ||
|> changeset(%{status: status, errors: errors}) | ||
|> Sanbase.Repo.update() | ||
end | ||
|
||
def by_uuid(uuid) do | ||
query = from(sync in __MODULE__, where: sync.uuid == ^uuid) | ||
|
||
case Sanbase.Repo.one(query) do | ||
nil -> {:error, "Sync with uuid #{uuid} not found"} | ||
sync -> {:ok, sync} | ||
end | ||
end | ||
|
||
def all_with_status(status) do | ||
from(sync in __MODULE__, where: sync.status == ^status) | ||
|> Sanbase.Repo.all() | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.