The associated Ruby script is more of a proof of concept to demonstrate using pipes and parameters in conjunction with the Rails runner. I have not fully verified that it works.
echo '<work_pid>' | bundle exec rails runner associate_pids_with_collection.rb -c <collection_pid>