Esempio n. 1
0
    def example():
        job = Job(job_id="123")
        pickled_rv = dumps({'results': None})
        yield job.save()
        yield job.connection.hset(job.key, 'result', pickled_rv)
        res = yield job.result
        my_log.debug('Job result %s', res)

        user = GoogleUser(_userid="1",
                          _token="asdasdf",
                          _refreshtoken="refreshtoken",
                          _resource="unknownresource",
                          _pushtoken="",
                          _badgenumber="0",
                          _pushsound="asdfasdfas",
                          _jid='*****@*****.**')
        my_log.info('User:%s before saving' % (user))
        res = yield user.save()
        my_log.info('User %s: saved. Res %s' % (user, res))
        ret = yield API(user.userid).login(user)
        my_log.info('Login result %s. Sleeping 10 seconds', ret)
        yield sleep(5)
        my_log.info('Result login %s', ret)
        try:
            ret = yield API(user.userid, conf.MACHINEID).logout(user.userid)
        except XMPPUserNotLogged as e:
            my_log.error('Exception launch %s', e)
        try:
            ret = yield API(user.userid).logout(user.userid)
        except XMPPUserNotLogged as e:
            my_log.error('Exception launch %s', e)

        #Perform a timeout
        ret = yield API(user.userid, 'default').login(user)
Esempio n. 2
0
    def post(self, key):
        self.constructor(key, login_arguments, metric=self.METRICS['post'])

        user = yield GoogleUser.load(key)
        user_to_logout = None

        pushtoken = self.args['_pushtoken']

        if user is None:
            if pushtoken:
                user_to_logout = yield GoogleUser.load(pushtoken=pushtoken)
        elif user.connected:
            if user.jid != self.args['_jid']:
                user_to_logout = user

        if not user_to_logout is None:
            if user is None:
                self.log.info('WEB_HANDLER_LOGOUT %s with the same pushtoken',
                              user_to_logout.userid)
            else:
                self.log.info('WEB_HANDLER_LOGOUT %s with other jid: %s->%s',
                              key, user.jid, self.args['_jid'])

            if user_to_logout.connected:
                yield API(key,
                          queue=user_to_logout.worker,
                          synchronous_call=True).logout(user_to_logout.userid)
            else:
                yield GoogleUser.remove(user_to_logout.userid)

            user = None

        try:
            response_data = {'success': False, 'reason': 'Already logged'}
            if user is None or not user.connected:
                if user and not user.connected:
                    yield GoogleUser.remove(user.userid, flush_messages=False)

                user = GoogleUser(_userid=key,
                                  _version=self.user_agent.version,
                                  _iosversion=self.user_agent.iosVersion,
                                  _hwmodel=self.user_agent.hwmodel,
                                  **self.args)
                yield API(key).login(user)
                response_data = {'success': True, 'reason': 'ok'}
        except XMPPUserAlreadyLogged:
            pass

        if self.FAKE_PURCHASE_ENABLED:
            self.perform_fakepurchase(userid=user.jid, deviceid=user.userid)

        response_data.update(
            dict(background_time=conf.XMPP_BACKGROUND_TIME,
                 resource_prefix=conf.XMPP_RESOURCE,
                 gtalk_priority=conf.XMPP_GTALK_PRIORITY,
                 ads_gift=self.FAKE_PURCHASE_ENABLED))
        self._response_json(response_data)
Esempio n. 3
0
 def delete(self, key):
     self.constructor(key, metric=self.METRICS['delete'])
     user = yield GoogleUser.load(key)
     if user is None:
         raise cyclone.web.HTTPError(404)
     if user.connected:
         yield API(key, queue=user.worker).logout(key)
     else:
         yield user.remove(user.userid)
     self._response_json({'success': True, 'reason': 'ok'})
Esempio n. 4
0
 def reloginUser(self, user, last_worker, removeWorker=False):
     try:
         pending_jobs = yield self.getPendingJobs(user.userid, last_worker)
         yield API(user.userid).relogin(user, pending_jobs)
     except Exception as e:
         self.log.err(e,
                      '[%s] Exception while reconnecting' % (user.userid))
     finally:
         if removeWorker:
             yield self.removeWorker(last_worker)
Esempio n. 5
0
    def put(self, key):
        self.constructor(key, contact_arguments, metric=self.METRICS['put'])
        user = yield GoogleUser.load(key)
        if user is None or not user.connected:
            raise cyclone.web.HTTPError(404)

        jid = self.args.pop('jid')
        try:
            yield API(key, queue=user.worker).update_contact(
                user.userid, jid, **self.args)
        except XMPPUserNotLogged as e:
            raise cyclone.web.HTTPError(500, str(e))
        self._response_json({'success': True, 'reason': 'ok'})
Esempio n. 6
0
 def delete(self, key):
     self.constructor(key, metric=self.METRICS['delete'])
     user = yield GoogleUser.load(key)
     if user is None:
         raise cyclone.web.HTTPError(404)
     #Remove messages from database (pending to implement)
     #update badgenumber
     try:
         yield GoogleMessage.flushMessages(key)
         if user.connected:
             yield API(key,
                       queue=user.worker).update(key, **{'badgenumber': 0})
         self._response_json({'success': True, 'reason': 'ok'})
     except XMPPUserNotLogged as e:
         raise cyclone.web.HTTPError(500, str(e))
Esempio n. 7
0
 def disconnectAwayUsers(self):
     away_users = yield GoogleUser.get_away()
     away_users = [] if not away_users else away_users
     self.log.info('CHECKING_AWAY_USERS: %s', len(away_users))
     for data in away_users:
         try:
             user = GoogleUser(**data)
             API(user.userid, queue=user.worker).disconnect(user.userid)
             APNSAPI(user.userid).sendpush(message=u'{0} {1}'.format(
                 u'\ue252',
                 translate.TRANSLATORS[user.lang]._('disconnected')),
                                           token=user.pushtoken,
                                           badgenumber=user.badgenumber,
                                           sound='')
             self.DISCONNECT_AWAY_METRIC.add(1)
         except Exception as e:
             self.log.err(
                 e, '[%s] Exception disconnecting user' % (data['_userid']))
Esempio n. 8
0
 def processOnMigrationUsers(self):
     onMigration_users = yield GoogleUser.get_onMigration()
     total_users = len(onMigration_users)
     if total_users > 0:
         self.log.info("ON_MIGRATION_USERS %s", total_users)
     now = datetime.utcnow()
     for data in onMigration_users:
         user = GoogleUser(**data)
         delta_time = now - user.onMigrationTime
         if delta_time.seconds < conf.XMPP_KEEP_ALIVE_TIME + 30:
             if 60 < delta_time.seconds < 70:
                 self.log.warning(
                     '[%s] USER_MIGRATION_STOPPED %s second(s) ago. Waiting to fix the problem with XMPP_KEEP_ALIVE. User state: %s',
                     user.userid, delta_time.seconds, user)
             continue
         self.log.warning(
             '[%s] USER_MIGRATION_STOPPED %s second(s) ago. Performing new relogin. User state: %s',
             user.userid, delta_time.seconds, user)
         user.worker = user.userid
         user.onMigrationTime = ''
         yield user.save()
         yield API(user.userid).relogin(user, pending_jobs=[])
Esempio n. 9
0
    def put(self, key):
        self.constructor(key, update_arguments, metric=self.METRICS['put'])
        user = yield GoogleUser.load(key)
        if user is None or not user.connected:
            raise cyclone.web.HTTPError(404)
        try:
            yield API(key, queue=user.worker).update(
                key,
                _version=self.user_agent.version,
                _iosversion=self.user_agent.iosVersion,
                _hwmodel=self.user_agent.hwmodel,
                **self.args)

            self._response_json({
                'success': True,
                'reason': 'ok',
                'background_time': conf.XMPP_BACKGROUND_TIME,
                'resource_prefix': conf.XMPP_RESOURCE,
                'gtalk_priority': conf.XMPP_GTALK_PRIORITY,
                'ads_gift': self.FAKE_PURCHASE_ENABLED
            })
        except XMPPUserNotLogged as e:
            raise cyclone.web.HTTPError(500, str(e))