I've read the Heroku page about custom clock processes where there's a web dyno and a clock dyno that runs certain jobs independently with an already-set schedule. What I need is to be able to schedule one-time jobs from the web dyno, i.e. a certain python object from that dyno must be accessible, and I'm not really clear on how these details could be implemented.
Currently, I have a worker dyno with several threads, where one of those threads is the one that does the jobs. This thread is started from the beginning if there's pending jobs. Otherwise, it's started by the main thread when there's a request for a job. From there on, the thread sleeps until it's time to do the job. This waiting can be interrupted by a new request from the main thread and it'll have to check when the next job will be. If there are no pending jobs, the thread ends its execution. The problem is that this approach is already consuming all my free-dyno hours and it doesn't seem a good way of doing things.
I've read this solution where APScheduler's add_job
is called from a web dyno, but I don't think that scheduler would even work when the web dyno is asleep, right? How could this be done?
I hope I explained myself well enough.