def expire_member_candidates(): """This is a cron job that removes any expired member candidates from NDB. This is not expected to ever find anything to delete, as there's no reason for them to not be successfully processed and removed. (But if they haven't been successfully processed after a day, they're not going to be, and we don't want stuff in our datastore that will be never removed.) """ logging.debug('self_serve.expire_member_candidates hit') gapps.validate_cron_task(flask.request) num_expired = MemberCandidate.clear_expireds() logging.info(f'Expiring {num_expired} MemberCandidate items') return flask.make_response('', 200)
def member_sheet_cull(): """Remove members from the members sheet who have not renewed in a long time. This gets called both as a cron job and a task queue job. """ if flask.request.method == 'GET': # cron job logging.debug('tasks.member_sheet_cull hit from cron') gapps.validate_cron_task(flask.request) else: # task queue job logging.debug('tasks.member_sheet_cull hit from task queue') gapps.validate_queue_task(flask.request) gapps.cull_members_sheet() return flask.make_response('', 200)
def process_mailchimp_updates(): """Updates MailChimp with changed members and volunteers. This gets called both as a cron job and a task queue job. """ if flask.request.method == 'GET': # cron job logging.debug('tasks.process_mailchimp_updates: hit from cron') gapps.validate_cron_task(flask.request) else: # task queue job logging.debug('tasks.process_mailchimp_updates: hit from task queue') gapps.validate_queue_task(flask.request) if not config.MAILCHIMP_ENABLED: return flask.make_response('', 200) gapps.process_mailchimp_updates() return flask.make_response('', 200)
def member_sheet_archive(): """Cron task that creates an archive of the members sheet once per year. """ logging.warning('tasks.member_sheet_archive: hit') gapps.validate_cron_task(flask.request) settings = Settings.singleton() logging.debug('tasks.member_sheet_archive: settings.member_sheet_year: %d', settings.member_sheet_year) new_year = gapps.archive_members_sheet(settings.member_sheet_year) if new_year: logging.debug( 'tasks.member_sheet_archive: archived; setting new year: %d', new_year) settings.member_sheet_year = new_year settings.update() return flask.make_response('', 200)
def renewal_reminder_emails(): """Sends renewal reminder emails to members who are nearing their renewal date. """ logging.debug('tasks.renewal_reminder_emails: hit') gapps.validate_cron_task(flask.request) expiring_rows = gapps.get_members_expiring_soon() if not expiring_rows: logging.debug('tasks.renewal_reminder_emails: no expiring members') return flask.make_response('', 200) logging.debug('tasks.renewal_reminder_emails: found %d expiring members', len(expiring_rows)) with open('templates/tasks/email-renewal-reminder-subject.txt', 'r') as subject_file: subject_noauto = subject_file.read().strip() with open('templates/tasks/email-renewal-reminder-auto-subject.txt', 'r') as subject_file: subject_auto = subject_file.read().strip() for row in expiring_rows: member_first_name = row.dict.get( config.SHEETS.member.fields.first_name.name) member_name = '%s %s' % ( member_first_name, row.dict.get(config.SHEETS.member.fields.last_name.name)) member_email = row.dict.get(config.SHEETS.member.fields.email.name) # Right now we use a Paypal button that does one-time purchases; # that is, members pay for a year and then need to manually pay # again the next year. But previously we used a "subscription" # Paypal button, so there are still some members who automatically # pay each year. These two groups will get different reminder # emails. auto_renewing = str( row.dict.get( config.SHEETS.member.fields.paypal_auto_renewing.name)) if auto_renewing.lower().startswith('y'): # Member is auto-renewing (i.e., is a Paypal "subscriber") subject = subject_auto body_html = flask.render_template( 'tasks/email-renewal-reminder-auto.jinja', app_config=config, member_first_name=row.dict.get( config.SHEETS.member.fields.first_name.name)) logging.info( 'tasks.renewal_reminder_emails: sending auto-renewing reminder to %s', member_email) else: # Member is year-to-year subject = subject_noauto body_html = flask.render_template( 'tasks/email-renewal-reminder.jinja', app_config=config, member_first_name=row.dict.get( config.SHEETS.member.fields.first_name.name)) logging.info( 'tasks.renewal_reminder_emails: sending non-auto-renewing reminder to %s', member_email) emailer.send((member_email, member_name), subject, body_html, None) return flask.make_response('', 200)