Browse Source

add disable_workers for tests to avoid staleentry errors

pull/26/head
Inhji Y. 2 years ago
parent
commit
9a34c8eb01
  1. 1
      apps/tomie_web/lib/tomie_web.ex
  2. 4
      apps/tomie_web/lib/tomie_web/controllers/bookmark_controller.ex
  3. 2
      apps/tomie_web/lib/tomie_web/controllers/profile_controller.ex
  4. 13
      apps/tomie_web/lib/tomie_web/worker.ex
  5. 3
      config/config.exs
  6. 3
      config/test.exs

1
apps/tomie_web/lib/tomie_web.ex

@ -23,6 +23,7 @@ defmodule TomieWeb do
import Plug.Conn
import TomieWeb.Gettext
alias TomieWeb.Router.Helpers, as: Routes
alias TomieWeb.Worker
end
end

4
apps/tomie_web/lib/tomie_web/controllers/bookmark_controller.ex

@ -18,7 +18,7 @@ defmodule TomieWeb.BookmarkController do
def create(conn, %{"bookmark" => bookmark_params}) do
case Bookmarks.create_bookmark(bookmark_params) do
{:ok, bookmark} ->
Que.add(Bookmarks.Worker, bookmark)
Worker.run(bookmark)
conn
|> put_flash(:info, @bookmark_created)
@ -69,7 +69,7 @@ defmodule TomieWeb.BookmarkController do
if user.token == token do
case Bookmarks.create_bookmark(%{source: url}) do
{:ok, bookmark} ->
Que.add(Bookmarks.Worker, bookmark)
Worker.run(bookmark)
conn
|> put_flash(:info, @bookmark_created)

2
apps/tomie_web/lib/tomie_web/controllers/profile_controller.ex

@ -22,7 +22,7 @@ defmodule TomieWeb.ProfileController do
{:ok, user} ->
conn
|> sync_user(user)
|> put_flash(:info, @tag_updated)
|> put_flash(:info, "Profile updated!")
|> redirect(to: Routes.profile_path(conn, :show))
{:error, changeset} ->

13
apps/tomie_web/lib/tomie_web/worker.ex

@ -0,0 +1,13 @@
defmodule TomieWeb.Worker do
def run(entity) do
disable_workers = Application.get_env(:tomie_web, :disable_workers)
unless disable_workers do
do_run(entity)
end
end
defp do_run(%Bookmarks.Bookmark{} = bookmark) do
Que.add(Bookmarks.Worker, bookmark)
end
end

3
config/config.exs

@ -18,7 +18,8 @@ config :tomie,
config :tomie_web,
ecto_repos: [Db.Repo],
generators: [context_app: :tomie]
generators: [context_app: :tomie],
disable_workers: false
# Configures the endpoint
config :tomie_web, TomieWeb.Endpoint,

3
config/test.exs

@ -14,5 +14,8 @@ config :tomie_web, TomieWeb.Endpoint,
http: [port: 4002],
server: false
config :tomie_web,
disable_workers: true
# Print only warnings and errors during test
config :logger, level: :warn