OZtree
OZtree copied to clipboard
Cron Job - move expired sponsorships out of main table
Option 1. Cron job to move them into expired reservations table Option 2. Make APIs look in both tables and account for whether species sponsorships are active or not in their returns - then make the action of clicking to sponsor something that's expired be the action that moves it to the expired reservations table and wipes the necessary fields to make that leaf available again
Option 1 is probably easier to implement but then requires another bit of complexity in the server admin side. We will likely need cron jobs anyway for e-mailing people to remind them about their sponsorship renewals. I'd therefore suggest option 1 - and I'll be speccing out the rest of the project based on this.
Therefore we need two Cron jobs
1.) copy expired sponsorships away from the reservations table and into the expired table ~~2.) send out necessary reminder e-mails~~ (see #439)
@lentinj if you have time in the upcoming sprint please can you write the scripts needed for these cron jobs?
The web2py-way of doing this would probably be the scheduler, a task-queue setup for managing workers (python process) that can run jobs. However, it feels fiddly to setup (you'd have to start/stop a separate python process, and have something to kickstart the jobs. Unless the reporting is something you really like, I think this isn't worth it.
Running a private/background_tasks.py script periodically would involve less moving parts, I'll put together an example of doing that. @hyanwong do you still use supervisord to manage the OneZoom processes?
I agree, a periodic script is better. I don't want to tie us in to the web2py ecosystem too hard.
Yes we use supervisord on the server.
@hyanwong The above adds a private/background_tasks.py that can be added to a supervisord config. I'm assuming you can guess what to add to README_SERVER.markdown easily enough based on the example at the top. If you want me to check then can do.
Make sure it autorestarts though, since errors in the script aren't handled. I figured if it is failing it would make more noise this way, and any future runs will have a cleaner environment.
Perfect, thanks.
~~This script should check if a species to be renewed is no longer in the tree - if it is no longer in the tree then we extend the sponsorship duration for 90 days in the hope that it reappears and knowing that no-one else can sponsor it nor should it be charged for renewal.~~ (#439)
@hyanwong I'm tagging you to take a quick look at this if possible before @lentinj starts on 22nd.
I've moved conversation about renewal reminder emails to #439. Leaving this open as a reminder that private/background_tasks.py needs to be added to the production supervisord config.
The above adds a grunt task runner for the script, so you can do: grunt exec:background_tasks:--single:--verbose without worrying about web2py incantations.