logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

rich_media_worker.ex (1283B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Workers.RichMediaWorker do
  5. alias Pleroma.Config
  6. alias Pleroma.Web.RichMedia.Backfill
  7. alias Pleroma.Web.RichMedia.Card
  8. use Oban.Worker, queue: :background, max_attempts: 3, unique: [period: :infinity]
  9. @impl true
  10. def perform(%Job{args: %{"op" => "expire", "url" => url} = _args}) do
  11. Card.delete(url)
  12. end
  13. def perform(%Job{args: %{"op" => "backfill", "url" => _url} = args}) do
  14. case Backfill.run(args) do
  15. :ok ->
  16. :ok
  17. {:error, type}
  18. when type in [:invalid_metadata, :body_too_large, :content_type, :validate, :get, :head] ->
  19. {:cancel, type}
  20. error ->
  21. {:error, error}
  22. end
  23. end
  24. # There is timeout value enforced by Tesla.Middleware.Timeout
  25. # which can be found in the RichMedia.Helpers module to allow us to detect
  26. # a slow/infinite data stream and insert a negative cache entry for the URL
  27. # We pad it by 2 seconds to be certain a slow connection is detected and we
  28. # can inject a negative cache entry for the URL
  29. @impl true
  30. def timeout(_job) do
  31. Config.get!([:rich_media, :timeout]) + :timer.seconds(2)
  32. end
  33. end