Running custom ruby scripts

One approach is to upload the file and then store the url in a setting. Uploading a file will prevent it getting deleted.

You can have a job run in a plugin. There are loads of examples of jobs in discourse and Pavilion plugins.