Created a test setup that works

This commit is contained in:
Kieran Eglin 2024-04-11 13:24:00 -07:00
parent 2c717e8e7e
commit d9d6066626
No known key found for this signature in database
GPG key ID: 193984967FCF432D
5 changed files with 92 additions and 1 deletions

View file

@ -22,4 +22,7 @@ alias Pinchflat.Metadata.MetadataFileHelpers
alias Pinchflat.SlowIndexing.FileFollowerServer
# TODO: remove
alias Pinchflat.KilledWorker
Pinchflat.Release.check_file_permissions()

View file

@ -8,7 +8,7 @@ FROM ${DEV_IMAGE}
# Install debian packages
RUN apt-get update -qq
RUN apt-get install -y inotify-tools ffmpeg curl git openssh-client \
python3 python3-pip python3-setuptools python3-wheel python3-dev locales
python3 python3-pip python3-setuptools python3-wheel python3-dev locales procps
# Install nodejs
RUN curl -sL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh

View file

@ -0,0 +1,58 @@
defmodule Pinchflat.KilledWorker do
@moduledoc false
use Oban.Worker,
queue: :default
import Ecto.Query, warn: false
require Logger
alias __MODULE__
alias Pinchflat.Repo
def kickoff(job_args \\ %{}, opts \\ []) do
job_args
|> KilledWorker.new(opts)
|> Repo.insert_unique_job()
:ok
end
def cancel do
Oban.Job
|> where(worker: "Pinchflat.KilledWorker")
|> Oban.cancel_all_jobs()
end
def start_stop do
kickoff()
Process.sleep(2000)
cancel()
end
@impl Oban.Worker
def perform(%Oban.Job{}) do
# case System.cmd("/app/wrapper.sh", ["/app/slow.sh"]) do
args = [
"/usr/local/bin/yt-dlp",
"https://www.youtube.com/@OverSimplified",
"--simulate",
"--print",
"%(title)s"
]
case System.cmd("/app/wrapper.sh", args) do
{output, 0} ->
Logger.warning("KilledWorker: #{output}")
{:ok, output}
{output, _} ->
Logger.error("KilledWorker: #{output}")
{:error, output}
end
Logger.warning("KilledWorker: done")
:ok
end
end

8
slow.sh Executable file
View file

@ -0,0 +1,8 @@
#!/bin/bash
# Runs for N seconds
for i in {1..15}; do
echo "Slow script running for $i seconds"
sleep 1
done
echo "Slow script done"

22
wrapper.sh Executable file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env bash
# Start the program in the background
exec "$@" &
pid1=$!
# Silence warnings from here on
exec >/dev/null 2>&1
# Read from stdin in the background and
# kill running program when stdin closes
exec 0<&0 $(
while read; do :; done
kill -KILL $pid1
) &
pid2=$!
# Clean up
wait $pid1
ret=$?
kill -KILL $pid2
exit $ret