Aguxez

Aguxez

I have an app that downloads songs from a playlist from Youtube, I’m using Porcelain with Youtube-dl, it was working correctly with a single user but I wanted to make it for more than one user (Still kinda private, so not much people) but I thought that, for example, if the app has 10 users at the same time downloading songs it would end up eating more resoures that desired, that’s where I thought about using Poolboy, I implemented it and it works how it’s supposed to UNTIL I have to download more songs.

Again, here’s how I implemented the download queue, first you pass the playlist ID then it fetch the songs on that playlist and splits them by 10 so each “user” will be downloading 10 songs at a time, when the 10 songs are downloaded then the next 10 ones are passed to the function that downloads them and so on until it’s all done.

Now, the problem, for testing I set up the size of the pool to 10 with a max_overflow of 12. The first 10 songs are downloaded correctly but once the next songs are pushed it doesn’t do anything. I’m guessing that poolboy doesn’t know that the process is already available and can be used by someone else? I’m not sure how I could make something to notify the availability of the process, the thing is that I don’t want any songs to be lost because a process wasn’t available at the time.

This is the GenServer in charge of downloading the songs.

defmodule Palsound.Service.Downloader do
  @moduledoc false

  use GenServer

  alias Porcelain.Process, as: Proc

  # API

  def start_link(_),
    do: GenServer.start_link(__MODULE__, [], [])

  def queue_and_download(songs, songs_path, thumb) do
    Enum.each(songs, fn(x) ->
      :poolboy.transaction(:worker_downloader, fn(pid) ->
        request = {:download, x, songs_path, thumb}
        GenServer.call(pid, request)
      end, :infinity)
    end)
  end

  # Server

  def init(state),
    do: {:ok, state}

  def handle_call({:download, song, songs_path, thumbnail}, _from, state) do
    thumbnail_value =
      case thumbnail do
        :no_thumbnail -> ""
        _ -> "--write-thumbnail"
      end

    %Proc{out: audio} =
      Porcelain.spawn(System.find_executable("youtube-dl"),
        ~w(-i --audio-format mp3 --extract-audio #{thumbnail_value}
          -o #{songs_path} #{song}), out: :stream)

    {:reply, audio, state}
  end
end

Showing Posts 1 to 2

gregvaughn

gregvaughn

Don’t pass :infinity to :poolboy.transaction That is masking whatever your underlying problem is.

I’m not quite positive enough to say “never” but you almost never want to use an infinite timeout. Ever.

Aguxez

Aguxez OP

Thanks, someone pointed that out and suggested a couple of solutions.

  1. Report it back to users telling them to wait
  2. Make a timeout really long so that it exceeds the song download length (Not really recommended, probably like a last resource)
  3. Have each worker, before downloading the song, give me an stimate of how long it’ll take to download the song and use it as a timeout so I can stimate when they’ll be free.

I’d opt for the third solution, now I need to figure out how to get the stimate.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews