def main(): log('cron2', 'Starting') connection = None try: connection, db = connect() message = Queue.get_message('payments') while message: payment_message = json.loads(message.get_body()) log('cron2', 'Got payment %s' % message.id, payment_message.get('subscription_id')) process_payment(db, message, payment_message) message = Queue.get_message('payments') finally: log('cron2', 'Finishing') if connection: connection.close()
def main(): connection = None # TODO: change i i = 0 log('cron3', 'Starting') try: connection, db = connect() message = Queue.get_message('notifications') while message is not None and i<20: notification_message = json.loads(message.get_body()) notify(db, message, notification_message) message = Queue.get_message('notifications') i+=1 finally: if connection: connection.close() log('cron3', 'Finishing')
def test_cron4_no_subscription(self): account = Accounts(self.db, { 'email': '*****@*****.**', 'password': '******', 'name': 'Daniel', 'startup': 'Payparrot', 'url': 'http://payparrot.com/', 'callback_url': 'http://www.epistemonikos.org', 'notification_url': 'http://www.epistemonikos.org', }) account.insert() parrot = Parrots(self.db, { 'twitter_id': '123123123', 'oauth_token': 'asd', 'oauth_token_secret': 'asdf', 'twitter_info': {}, 'payments': [], 'twitter_info': { 'screen_name': 'danielgua' } }) parrot.insert() subscription = Subscriptions(self.db, {'account_id': account.id, 'active': False, 'parrot_id': parrot.id, 'twitter_screen_name': parrot.twitter_info.get("screen_name")}) subscription.insert() last_date = datetime.now(); next_action_date = last_date; next_payment = NextPayments(self.db, { 'account_id': account.id, 'parrot_id': parrot.id, 'action_date': next_action_date }); next_payment.insert() from payparrot_scripts.crons.cron4 import main as cron4 cron4() message = Queue.get_message('payments') self.assertFalse(message) self.assertEqual(0, self.db.next_payments.find({'_id': next_payment.id}).count())