Пример #1
0
def main():
    connection = None
    log('cron4', 'Starting')
    try:
        connection, db = connect()
        next_payments = NextPayments.find(
            db, {'action_date': {'$lte': datetime.now()}}, {'parrot_id':1,'account_id':1,'_id':1}
        ).sort([('_id', -1)])
        
        for next_payment in next_payments:
            subscription = Subscriptions.findOne(db, {'account_id': next_payment.get('account_id'), 'parrot_id': next_payment.get('parrot_id')})
            if subscription and subscription.active:
                created_message = Queue.insert(
                    'payments', 
                    {
                        'subscription_id': str(subscription.id),
                        'account_id': str(subscription.account_id),
                        'parrot_id': str(subscription.parrot_id)
                    }
                )
                if created_message:
                    db.next_payments.remove({'_id': next_payment.get('_id')})
            else:
                db.next_payments.remove({'_id': next_payment.get('_id')})
    finally:
        if connection:
            connection.close()
        log('cron4', 'Finishing')
Пример #2
0
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()
Пример #3
0
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')
Пример #4
0
def main():
    connection = None
    try:
        log('cron1', 'Starting')
        connection, db = connect()
        subscriptions = Subscriptions.find(db, {'active': True, 'first_tweet': False})
        for subscription_raw in subscriptions:
            created_message = Queue.insert(
                'payments', 
                {
                    'subscription_id': str(subscription_raw['_id']),
                    'account_id': str(subscription_raw['account_id']),
                    'parrot_id': str(subscription_raw['parrot_id'])
                }
            )
            log('cron1', 'Payment queued %s' % created_message.id, subscription_raw['_id'])
            db.subscriptions.update({'_id': subscription_raw['_id']}, {'$set': {'first_tweet': True}})
            log('cron1', 'Subscription updated', subscription_raw['_id'])
    finally:
        if connection:
            connection.close()
        log('cron1', 'Finishing')
Пример #5
0
def connect_to_mongo():
    return connect()
Пример #6
0
	def get_mongo(self):
		"Retrieve the mongo instance from the environment"
		if self.mongo_db: 
			return self.mongo_db
		self.connection, self.mongo_db = connect()
		return self.mongo_db