Skip to content

Commit

Permalink
chore: remove FLAME and add ash_paper_trail
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Jan 31, 2024
1 parent 650d168 commit 5885c12
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 127 deletions.
128 changes: 66 additions & 62 deletions assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,140 +9,144 @@
@import "./_components.css";

@layer components {
.aspect-video {
@apply max-w-lg
}
.aspect-video {
@apply max-w-lg
}
}

.aspect-video {
max-width: 500px;
}

.search-hit {
@apply text-primary-light-500 dark:text-primary-dark-300
@apply text-primary-light-500 dark:text-primary-dark-300
}

@layer components {
.prose li p {
@apply m-0;
}
.prose li p {
@apply m-0;
}
}

/* Alerts and form errors used by phx.new */
.alert {
padding: 15px;
margin-bottom: 20px;
border: 1px solid transparent;
border-radius: 4px;
padding: 15px;
margin-bottom: 20px;
border: 1px solid transparent;
border-radius: 4px;
}

.alert-info {
color: #31708f;
background-color: #d9edf7;
border-color: #bce8f1;
color: #31708f;
background-color: #d9edf7;
border-color: #bce8f1;
}

.alert-warning {
color: #8a6d3b;
background-color: #fcf8e3;
border-color: #faebcc;
color: #8a6d3b;
background-color: #fcf8e3;
border-color: #faebcc;
}

.alert-danger {
color: #a94442;
background-color: #f2dede;
border-color: #ebccd1;
color: #a94442;
background-color: #f2dede;
border-color: #ebccd1;
}

.alert p {
margin-bottom: 0;
margin-bottom: 0;
}

.alert:empty {
display: none;
display: none;
}

.invalid-feedback {
color: #a94442;
display: block;
margin: -1rem 0 2rem;
color: #a94442;
display: block;
margin: -1rem 0 2rem;
}

/* LiveView specific classes for your customization */
.phx-no-feedback.invalid-feedback,
.phx-no-feedback .invalid-feedback {
display: none;
display: none;
}

.phx-click-loading {
opacity: 0.5;
transition: opacity 1s ease-out;
opacity: 0.5;
transition: opacity 1s ease-out;
}

.phx-loading {
cursor: wait;
cursor: wait;
}

.phx-modal {
opacity: 1 !important;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0, 0, 0, 0.4);
opacity: 1 !important;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0, 0, 0, 0.4);
}

.phx-modal-content {
background-color: #fefefe;
margin: 15vh auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
background-color: #fefefe;
margin: 15vh auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}

.phx-modal-close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}

.phx-modal-close:hover,
.phx-modal-close:focus {
color: black;
text-decoration: none;
cursor: pointer;
color: black;
text-decoration: none;
cursor: pointer;
}


/* Prevent scrolling beneath Topbar due to URL fragment */
html {
scroll-padding-top: 8.5rem;
scroll-padding-top: 8.5rem;
}

@media (min-width: 1280px) {
html {
scroll-padding-top: 5rem;
}
html {
scroll-padding-top: 5rem;
}
}

html {
scroll-behavior: smooth;
scroll-behavior: smooth;
}

/* Ensure dark-mode is applied to native elements, eg scrollbars */
.dark {
color-scheme: dark;
color-scheme: dark;
}

/* Constrain sidebar container size to screen height - Topbar height - mobile button height*/
.sidebar-container {
max-height: calc(100vh - 8.5rem);
max-height: calc(100vh - 8.5rem);
}

@media (min-width: 1280px) {

/* Constrain sidebar container size to screen height - Topbar height */
.sidebar-container {
max-height: calc(100vh - 5rem);
}
}
/* Constrain sidebar container size to screen height - Topbar height */
.sidebar-container {
max-height: calc(100vh - 5rem);
}
}
11 changes: 1 addition & 10 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,14 @@ if config_env() == :prod do
For example: ecto://USER:PASS@HOST/DATABASE
"""

pool_size =
if FLAME.Parent.get() do
3
else
String.to_integer(System.get_env("POOL_SIZE") || "10")
end
pool_size = String.to_integer(System.get_env("POOL_SIZE") || "10")

config :ash_hq, AshHq.Repo,
ssl: false,
url: database_url,
pool_size: pool_size,
socket_options: [:inet6]

config :flame, :backend, FLAME.FlyBackend
config :flame, FLAME.FlyBackend, token: System.fetch_env!("FLY_API_TOKEN")
config :flame, :terminator, shutdown_timeout: :timer.seconds(30)

# The secret key base is used to sign/encrypt cookies and other secrets.
# A default value is used in config/dev.exs and config/test.exs but you
# want to use a different value for prod and you most likely don't want
Expand Down
16 changes: 6 additions & 10 deletions lib/ash_hq/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@ defmodule AshHq.Application do

@impl true
def start(_type, _args) do
flame_parent = FLAME.Parent.get()

Appsignal.Phoenix.LiveView.attach()

# topologies = Application.get_env(:libcluster, :topologies) || []

children =
[
{FLAME.Pool,
name: AshHq.ImporterPool, min: 0, max: 1, max_concurrency: 6, idle_shutdown_after: 30_000},
!flame_parent && Supervisor.child_spec({Finch, name: AshHq.Finch}, id: AshHq.Finch),
!flame_parent && Supervisor.child_spec({Finch, name: Swoosh.Finch}, id: Swoosh.Finch),
Supervisor.child_spec({Finch, name: AshHq.Finch}, id: AshHq.Finch),
Supervisor.child_spec({Finch, name: Swoosh.Finch}, id: Swoosh.Finch),
AshHq.Vault,
# Start the Ecto repository
AshHq.Repo,
Expand All @@ -29,11 +25,11 @@ defmodule AshHq.Application do
# Start the Endpoint (http/https)
AshHqWeb.Endpoint,
{AshHq.Docs.Library.Agent, nil},
# !flame_parent && {Cluster.Supervisor, [topologies, [name: AshHq.ClusterSupervisor]]},
# {Cluster.Supervisor, [topologies, [name: AshHq.ClusterSupervisor]]},
{Haystack.Storage.ETS, storage: AshHq.Docs.Indexer.storage()},
!flame_parent && AshHq.Docs.Indexer,
!flame_parent && oban_worker(),
!flame_parent && Application.get_env(:ash_hq, :discord_bot) && AshHq.Discord.Supervisor
AshHq.Docs.Indexer,
oban_worker(),
Application.get_env(:ash_hq, :discord_bot) && AshHq.Discord.Supervisor
]
|> Enum.filter(& &1)

Expand Down
12 changes: 0 additions & 12 deletions lib/ash_hq/docs/resources/library/library.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ defmodule AshHq.Docs.Library do
]
end

change fn changeset, _ ->
Ash.Changeset.around_transaction(changeset, fn changeset, func ->
FLAME.call(
AshHq.ImporterPool,
fn ->
func.(changeset)
end,
timeout: :timer.minutes(10)
)
end)
end

manual AshHq.Docs.Library.Actions.Import
end
end
Expand Down
64 changes: 31 additions & 33 deletions lib/ash_hq/github/contributor/actions/import.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,41 @@ defmodule AshHq.Github.Contributor.Actions.Import do
require Logger

def run(_input, _, _) do
FLAME.call(AshHq.ImporterPool, fn ->
AshHq.Docs.Library
|> AshHq.Docs.read!()
|> Stream.flat_map(fn library ->
:timer.sleep(1000)
opts = []
AshHq.Docs.Library
|> AshHq.Docs.read!()
|> Stream.flat_map(fn library ->
:timer.sleep(1000)
opts = []

opts =
if api_key = Application.get_env(:ash_hq, :github)[:api_key] do
Keyword.put(opts, :headers, [{"Authorization", "token #{api_key}"}])
else
opts
end
opts =
if api_key = Application.get_env(:ash_hq, :github)[:api_key] do
Keyword.put(opts, :headers, [{"Authorization", "token #{api_key}"}])
else
opts
end

"https://api.github.com/repos/#{library.repo_org}/#{library.name}/contributors"
|> Req.get!(opts)
|> case do
%{status: 200, body: body} ->
Stream.map(body, &Map.take(&1, ["id", "avatar_url", "html_url", "login"]))
"https://api.github.com/repos/#{library.repo_org}/#{library.name}/contributors"
|> Req.get!(opts)
|> case do
%{status: 200, body: body} ->
Stream.map(body, &Map.take(&1, ["id", "avatar_url", "html_url", "login"]))

resp ->
Logger.error("Invalid response from GH: #{inspect(resp)}")
[]
end
end)
|> Stream.with_index()
|> Stream.map(fn {contributor, index} ->
Map.put(contributor, "order", index)
end)
|> Stream.uniq_by(&Map.get(&1, "id"))
|> AshHq.Github.bulk_create(AshHq.Github.Contributor, :create,
upsert?: true,
upsert_fields: [:order, :login, :avatar_url, :html_url],
return_errors?: true,
stop_on_error?: true
)
resp ->
Logger.error("Invalid response from GH: #{inspect(resp)}")
[]
end
end)
|> Stream.with_index()
|> Stream.map(fn {contributor, index} ->
Map.put(contributor, "order", index)
end)
|> Stream.uniq_by(&Map.get(&1, "id"))
|> AshHq.Github.bulk_create(AshHq.Github.Contributor, :create,
upsert?: true,
upsert_fields: [:order, :login, :avatar_url, :html_url],
return_errors?: true,
stop_on_error?: true
)

{:ok, :ok}
rescue
Expand Down
14 changes: 14 additions & 0 deletions priv/repo/seeds.exs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ AshHq.Docs.Library.create!(
upsert_identity: :unique_name
)

AshHq.Docs.Library.create!(
%{
name: "ash_paper_trail",
display_name: "AshPaperTrail",
module_prefixes: ["AshPaperTrail"],
order: 86,
description: """
Creates and manage a version tracking resource for a given resource.
"""
},
upsert?: true,
upsert_identity: :unique_name
)

AshHq.Docs.Library.create!(
%{
name: "ash_money",
Expand Down

0 comments on commit 5885c12

Please sign in to comment.