def test_hour_old_memento_queued(self): m = Memento("new") save(m) m.created_at -= timedelta(0, 3600) # one hour ago save(m) assert_equal(len(Memento.queue()), 1) qi = Memento.queue()[0] assert_equal(qi.threshold.name, 'hour') assert_equal(qi.memento, m)
def test_hour_old_memento_queued(self): m = Memento("new") save(m) m.created_at -= timedelta(0, 3600) # one hour ago save(m) assert_equal(len(Memento.queue()), 1) qi = Memento.queue()[0] assert_equal(qi.threshold.name, "hour") assert_equal(qi.memento, m)
def send_pending(): sms = Clockwork(current_app.config['CLOCKWORK_API_KEY']) to = current_app.config['CLOCKWORK_TO'] from_ = current_app.config['CLOCKWORK_FROM'] should_send_sms = current_app.config['SUPPRESS_SMS'] is None for item in Memento.queue(): time = item.threshold.desc text = item.memento.text msg = '{0} ago: {1}'.format(time, text) log.info('Sending SMS: memento={0} threshold={1} msg="{2}"'.format(item.memento.id, item.threshold.name, msg)) if should_send_sms: res = sms.send(to, msg, from_=from_) if not res.ok: for err in res.errors: log.error('Clockwork error: %s', err) else: setattr(item.memento, item.threshold.name, True) db.session.commit() # Just assume everything would have worked if we're suppressing SMS # sending else: setattr(item.memento, item.threshold.name, True) db.session.commit()
def debug(): items = [] for qi in Memento.queue(): items.append({'id': qi.memento.id, 'type': qi.threshold.name}) return jsonify({'items': items})
def test_week_old_memento_queued(self): m = Memento("new") save(m) m.created_at -= timedelta(7) # one week ago save(m) assert_equal(len(Memento.queue()), 3) qi_hour, qi_day, qi_week = Memento.queue() assert_equal(qi_hour.threshold.name, 'hour') assert_equal(qi_hour.memento, m) assert_equal(qi_day.threshold.name, 'day') assert_equal(qi_day.memento, m) assert_equal(qi_week.threshold.name, 'week') assert_equal(qi_week.memento, m)
def test_week_old_memento_queued(self): m = Memento("new") save(m) m.created_at -= timedelta(7) # one week ago save(m) assert_equal(len(Memento.queue()), 3) qi_hour, qi_day, qi_week = Memento.queue() assert_equal(qi_hour.threshold.name, "hour") assert_equal(qi_hour.memento, m) assert_equal(qi_day.threshold.name, "day") assert_equal(qi_day.memento, m) assert_equal(qi_week.threshold.name, "week") assert_equal(qi_week.memento, m)
def test_new_memento_unqueued(self): m = Memento("new") save(m) assert_equal(Memento.queue(), [])