-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
0.2.0 Introduce client Clone task #12
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1e69564
Introduce Clone task
sovetnik 52dcbd6
Fix style
sovetnik ee7ac96
Add their own Supervisors for Fetchers and Writers
sovetnik f61539e
Write umwelt files directly in lib and test
sovetnik d23154e
Update deps
sovetnik 26d1906
Possible fix blinking test
sovetnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ jobs: | |
strategy: | ||
matrix: | ||
elixir: [1.17.2] | ||
otp: [26.2.5.1, 27.0] | ||
otp: [26.2.5.1, 27.0.1] | ||
steps: | ||
- name: Cancel Previous Runs | ||
uses: styfle/[email protected] | ||
|
@@ -61,7 +61,7 @@ jobs: | |
strategy: | ||
matrix: | ||
elixir: [1.17.2] | ||
otp: [26.2.5.1, 27.0] | ||
otp: [26.2.5.1, 27.0.1] | ||
steps: | ||
- name: Cancel Previous Runs | ||
uses: styfle/[email protected] | ||
|
@@ -126,7 +126,7 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
elixir: [1.17.2] | ||
otp: [26.2.5.1, 27.0] | ||
otp: [26.2.5.1, 27.0.1] | ||
steps: | ||
- name: Cancel Previous Runs | ||
uses: styfle/[email protected] | ||
|
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
elixir 1.17.2 | ||
erlang 27.0 | ||
erlang 27.0.1 |
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,79 @@ | ||
defmodule Mix.Tasks.Umwelt.Clone do | ||
@moduledoc "Clones phase modules and code" | ||
@shortdoc "The code puller" | ||
use Mix.Task | ||
require Logger | ||
|
||
@impl Mix.Task | ||
def run([phase_id]) do | ||
case System.get_env("UMWELT_TOKEN", "no_token") do | ||
"no_token" -> | ||
""" | ||
Token not found in env! | ||
You can get it on umwelt.dev/auth/profile and do | ||
|
||
export UMWELT_TOKEN="token" | ||
|
||
or pass it directly in | ||
|
||
mix clone phase_id "token" | ||
|
||
""" | ||
|> Logger.warning() | ||
|
||
token -> | ||
run([phase_id, token]) | ||
end | ||
end | ||
|
||
@impl Mix.Task | ||
def run([phase_id, token]) do | ||
Umwelt.Client.Application.start(nil, nil) | ||
sovetnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Umwelt.Client.Supervisor | ||
|> Process.whereis() | ||
|> Process.monitor() | ||
sovetnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
%{phase_id: phase_id, token: token} | ||
|> assign_host() | ||
|> assign_port() | ||
|> Umwelt.Client.pull() | ||
|
||
receive do | ||
{:DOWN, _, :process, _, _} -> | ||
Logger.info("Done!") | ||
|
||
other -> | ||
Logger.warning(inspect(other)) | ||
end | ||
end | ||
|
||
defp assign_host(params) do | ||
host = | ||
case Mix.env() do | ||
:dev -> | ||
System.get_env("UMWELT_HOST", "https://umwelt.dev") | ||
|
||
:test -> | ||
"http://localhost" | ||
sovetnik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
Map.put(params, :api_host, host) | ||
end | ||
|
||
defp assign_port(params) do | ||
port = | ||
case Mix.env() do | ||
:dev -> | ||
case params.api_host do | ||
"http://localhost" -> 4000 | ||
"https://umwelt.dev" -> 443 | ||
end | ||
|
||
:test -> | ||
Application.get_env(:umwelt, :api_port) | ||
end | ||
|
||
Map.put(params, :port, port) | ||
end | ||
end |
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,11 @@ | ||
defmodule Umwelt.Client do | ||
@moduledoc "Client for umwelt.dev" | ||
|
||
alias Umwelt.Client.Clone | ||
|
||
require Logger | ||
|
||
def pull(params) do | ||
GenServer.cast(Clone, {:pull, params}) | ||
end | ||
end |
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,93 @@ | ||
defmodule Umwelt.Client.Agent do | ||
@moduledoc "Keeps pulling metadata" | ||
|
||
use Agent | ||
require Logger | ||
|
||
def start_link(_args) do | ||
Agent.start_link( | ||
fn -> | ||
%{ | ||
modules: %{}, | ||
waiting: [], | ||
fetching: [], | ||
fetched: [], | ||
writing: [], | ||
written: [], | ||
total: 0 | ||
} | ||
end, | ||
name: __MODULE__ | ||
) | ||
end | ||
|
||
def all_waiting, do: Agent.get(__MODULE__, fn state -> state.waiting end) | ||
|
||
def completed?, | ||
do: Agent.get(__MODULE__, fn state -> state.total == Enum.count(state.written) end) | ||
|
||
def state, do: Agent.get(__MODULE__, fn state -> state end) | ||
def total, do: Agent.get(__MODULE__, fn state -> state.total end) | ||
def ready, do: Agent.get(__MODULE__, fn state -> Enum.count(state.written) end) | ||
|
||
def add_modules(modules) do | ||
Agent.update(__MODULE__, fn state -> | ||
%{ | ||
state | ||
| modules: modules, | ||
waiting: Map.keys(modules), | ||
fetching: [], | ||
fetched: [], | ||
writing: [], | ||
written: [], | ||
total: map_size(modules) | ||
} | ||
end) | ||
end | ||
|
||
def next_waiting do | ||
Agent.get_and_update(__MODULE__, fn state -> | ||
case state.waiting do | ||
[mod_name | modules] -> | ||
{ | ||
%{id: state.modules[mod_name], name: mod_name}, | ||
state | ||
|> Map.put(:waiting, modules) | ||
|> Map.put(:fetching, [mod_name | state.fetching]) | ||
} | ||
|
||
[] -> | ||
{nil, state} | ||
end | ||
end) | ||
end | ||
|
||
def update_status(mod_name, :fetched) do | ||
Agent.update(__MODULE__, fn state -> | ||
state | ||
|> Map.put(:fetching, List.delete(state.fetching, mod_name)) | ||
|> Map.put(:fetched, [mod_name | state.fetched]) | ||
end) | ||
end | ||
|
||
def update_status(mod_name, :writing) do | ||
Agent.update(__MODULE__, fn state -> | ||
state | ||
|> Map.put(:writing, [mod_name | state.writing]) | ||
end) | ||
end | ||
|
||
def update_status(mod_name, :written) do | ||
Agent.update(__MODULE__, fn state -> | ||
state | ||
|> Map.put(:writing, List.delete(state.writing, mod_name)) | ||
|> Map.put(:written, [mod_name | state.written]) | ||
end) | ||
|
||
render_progress() | ||
end | ||
|
||
def render_progress do | ||
ProgressBar.render(ready(), total(), suffix: :count) | ||
end | ||
end |
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,15 @@ | ||
defmodule Umwelt.Client.Application do | ||
@moduledoc "Client app & Supervisor" | ||
|
||
use Application | ||
|
||
def start(_type, _args) do | ||
children = [ | ||
{Umwelt.Client.Agent, []}, | ||
{Umwelt.Client.Clone, []} | ||
] | ||
|
||
opts = [strategy: :one_for_one, name: Umwelt.Client.Supervisor] | ||
Supervisor.start_link(children, opts) | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mix.shell.info/1
makes it fancier, see this for an inspiration.