Browse Source

fix(tweak): Webmention and editor config updates.

jackyalcine 7 months ago
parent
commit
541b2b9515
Signed by: Jacky Alciné <yo@jacky.wtf> GPG Key ID: 537A4F904B15268D
9 changed files with 36 additions and 33 deletions
  1. 1
    1
      .editorconfig
  2. 1
    1
      .formatter.exs
  3. 1
    1
      config/config.exs
  4. 1
    2
      config/dev.exs
  5. 3
    0
      docker/scripts/post-deploy.sh
  6. 1
    1
      lib/job.ex
  7. 18
    22
      lib/job/webmention.ex
  8. 8
    3
      lib/repo/webmention.ex
  9. 2
    2
      mix.exs

+ 1
- 1
.editorconfig View File

@@ -5,7 +5,7 @@ charset = utf-8
5 5
 indent_style = space
6 6
 indent_size = 2
7 7
 end_of_line = lf
8
-insert_final_newline = true
8
+insert_final_newline = false
9 9
 line_length = 80
10 10
 
11 11
 [*.markdown,*.md]

+ 1
- 1
.formatter.exs View File

@@ -18,5 +18,5 @@
18 18
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 19
 [
20 20
   inputs: ["mix.exs", "{web,config,lib,test}/**/*.{ex,exs}"],
21
-  line_length: 120,
21
+  line_length: 100
22 22
 ]

+ 1
- 1
config/config.exs View File

@@ -84,7 +84,7 @@ config :koype, :phoenix_swagger,
84 84
 
85 85
 config :liquid, error_mode: :strict
86 86
 
87
-config :mnesia, dir: 'priv/repo/mnesia/#{Mix.env()}/#{node()}'
87
+config :mnesia, dir: 'priv/mnesia/#{Mix.env()}/#{node()}'
88 88
 
89 89
 config :indieweb,
90 90
   webmention_url_adapter: Koype.Webmention.URIAdapter,

+ 1
- 2
config/dev.exs View File

@@ -22,8 +22,7 @@ config :koype, Koype.Web.Endpoint,
22 22
     ]
23 23
   ]
24 24
 
25
-config :logger, :console, format: {PrettyPrintFormatter, :write}
26
-config :logger, level: :info
25
+config :logger, level: :debug
27 26
 
28 27
 config :phoenix, :stacktrace_depth, 50
29 28
 

+ 3
- 0
docker/scripts/post-deploy.sh View File

@@ -3,5 +3,8 @@
3 3
 echo " ----> [deploy:post] Creating database file..."
4 4
 touch "/opt/koype/priv/repo/db/${MIX_ENV:-prod}.db" || exit 15
5 5
 
6
+echo " ----> [deploy:post] Creating job peristence database..."
7
+mix que.setup
8
+
6 9
 echo " ----> [deploy:post] Setting up database..."
7 10
 mix ecto.setup || exit 20

+ 1
- 1
lib/job.ex View File

@@ -45,7 +45,7 @@ defmodule Koype.Job do
45 45
   end
46 46
 
47 47
   defmodule Worker do
48
-    use Que.Worker, concurrency: 20
48
+    use Que.Worker, concurrency: 100
49 49
 
50 50
     # TODO: Do exception handling around this.
51 51
     def perform(kind: kind, job: job) do

+ 18
- 22
lib/job/webmention.ex View File

@@ -70,7 +70,7 @@ defmodule Koype.Job.Webmention do
70 70
     def execute(_) do
71 71
       Koype.Repo.Webmention
72 72
       |> Koype.Repo.all()
73
-      |> Enum.each(fn webmention ->
73
+      |> Enum.map(fn webmention ->
74 74
         target =
75 75
           URI.merge(Koype.host(), String.trim_leading(webmention.target, "/") |> String.replace_prefix("", "/"))
76 76
           |> URI.to_string()
@@ -81,29 +81,25 @@ defmodule Koype.Job.Webmention do
81 81
           "Reparsing Webmention #{webmention.id} to have come from #{source} to #{target} (#{webmention.target})."
82 82
         )
83 83
 
84
-        author_task =
85
-          Task.async(fn ->
86
-            with(
87
-              {:ok, updated_model} <- Koype.Repo.Webmention.update_author(webmention),
88
-              _ <-
89
-                Logger.info(
90
-                  "Updated the author for Webmention ##{webmention.id} from #{webmention.author} to #{
91
-                    updated_model.author
92
-                  }."
93
-                ),
94
-              {:ok, _} <- IndieWeb.HCard.resolve(updated_model.author)
95
-            ) do
96
-              Logger.info("Cached author information for Webmention ##{webmention.id}.")
97
-            else
98
-              _ ->
99
-                Logger.info("The author for Webmention #{webmention.id} was not updated.")
100
-                nil
101
-            end
102
-          end)
103
-
104 84
         Koype.Webmention.receive(source: source, target: target)
105
-        Task.await(author_task)
85
+
86
+        Task.async(fn ->
87
+          case Koype.Repo.Webmention.update_author(webmention) do
88
+            {:ok, updated_model} ->
89
+              Logger.info(
90
+                "Updated the author for Webmention ##{webmention.id} from #{webmention.author} to #{
91
+                  updated_model.author
92
+                }."
93
+              )
94
+
95
+            _ ->
96
+              Logger.info("The author for Webmention #{webmention.id} was not updated.")
97
+          end
98
+        end)
106 99
       end)
100
+      |> Enum.each(&Task.await/1)
101
+
102
+      :ok
107 103
     end
108 104
 
109 105
     def info(_) do

+ 8
- 3
lib/repo/webmention.ex View File

@@ -120,7 +120,7 @@ defmodule Koype.Repo.Webmention do
120 120
 
121 121
   def update(model, args) do
122 122
     with(
123
-      cs <- changeset(model, %{}) |> change(args |> Keyword.drop(~w(mf2)a)),
123
+      cs <- model |> changeset(%{}) |> change(args |> Keyword.drop(~w(mf2)a)),
124 124
       {:ok, record} <- Koype.Repo.update(cs),
125 125
       :ok <- do_update_json(model, args)
126 126
     ) do
@@ -140,8 +140,13 @@ defmodule Koype.Repo.Webmention do
140 140
 
141 141
   defp do_update_json(model, [mf2: mf2] = _args) when is_map(mf2) do
142 142
     case Koype.Repo.Webmention.Json.persist(model, mf2) do
143
-      {:ok, _} -> :ok
144
-      error -> error
143
+      {:ok, _} ->
144
+        Logger.info("Updated MF2 of Webmention ##{model.id}.", mf2: mf2)
145
+        :ok
146
+
147
+      error ->
148
+        Logger.info("Failed to update MF2 of Webmention ##{model.id}.", error: inspect(error))
149
+        error
145 150
     end
146 151
   end
147 152
 

+ 2
- 2
mix.exs View File

@@ -143,7 +143,6 @@ defmodule Koype.Mixfile do
143 143
       {:phoenix_pubsub, "~> 1.1"},
144 144
       {:phoenix_swagger, "~> 0.8.1"},
145 145
       {:plug_cowboy, "~> 2.0"},
146
-      {:pretty_print_formatter, "~> 0.1.5", only: :dev},
147 146
       {:que, "~> 0.8.0"},
148 147
       {:readability, "~> 0.10.0"},
149 148
       {:scrivener_list, "~> 1.0"},
@@ -170,7 +169,8 @@ defmodule Koype.Mixfile do
170 169
       "test.features": ["ecto.create --quiet", "ecto.migrate", "test --only integration:true"],
171 170
       lint: ["credo", "sobelow", "dialyzer --plt"],
172 171
       start: ["phx.server"],
173
-      ci: ["coveralls", "test", "test.features", "lint"]
172
+      ci: ["coveralls", "test", "test.features", "lint"],
173
+      routes: ["phx.routes Koype.Web.Router"]
174 174
     ]
175 175
   end
176 176
 end

Loading…
Cancel
Save