def snoozePushTime(self, value): if value: seconds = int(value) self._snoozePushTime = Timer().utcnow() + timedelta( seconds=seconds) if seconds else Timer().utcnow() + timedelta( days=365) else: self._snoozePushTime = None
def __init__(self, userid, fromid, msgid, data): self.userid = userid self.fromid = fromid self.msgid = msgid self.data = data self.time = Timer().isoformat() self.removeTime = None
def away(self, value): self._away = bool(value) if self._away: if self._lastTimeConnected is None: self._lastTimeConnected = Timer().utcnow() else: self._lastTimeConnected = None
def notifyWhenAvailable(self, value): if value: seconds = int(value) self._notifyWhenAvailable = Timer().utcnow() + timedelta( seconds=seconds) else: self._notifyWhenAvailable = None
def relogin(self, xmppuser, pending_jobs): len_pending_jobs = len(pending_jobs) self.log.info('RELOGIN %s. Pending_Jobs: %s. Data: %s', xmppuser.jid, len_pending_jobs, xmppuser) try: yield self._shared_login(xmppuser) running_client = KatooApp().getService(xmppuser.userid) self.log.info('RELOGIN %s. Running xmppclient: %s', xmppuser.jid, running_client) except XMPPUserAlreadyLogged: #If user is already logged xmppuser data is valid and we take it as xmppuser running_client = KatooApp().getService(xmppuser.userid) self.log.warning('RELOGIN %s. User Already logged taking user to perform RELOGIN process. Running xmppclient: %s', xmppuser.jid, running_client) xmppuser = running_client.user xmppuser.worker = xmppuser.userid try: xmppuser.onMigrationTime = Timer().utcnow() res = yield xmppuser.save() self.log.info('perform relogin %s. Enqueuing pending jobs %s before migration was launched. Data %s. Save result: %s', xmppuser.jid, len_pending_jobs, running_client, res) queue = Queue(conf.MACHINEID) #Enqueue pending jobs before migration was launched for job_id in pending_jobs: try: job = yield Job.fetch(job_id, queue.connection) yield queue.enqueue_job(job) except NoSuchJobError: pass self.log.info('perform relogin %s. Finished enqueuing pending jobs before migration was launched.', xmppuser.jid) self.log.info('perform relogin %s. Enqueing pending jobs after migration was launched.', xmppuser.jid) #Enqueue pending jobs after migration was launched migration_queue = Queue(xmppuser.userid) migration_job_ids = yield migration_queue.job_ids yield migration_queue.empty() while migration_job_ids: job_id = migration_job_ids.pop(0) try: job = yield Job.fetch(job_id, migration_queue.connection) #Enqueue job in current worker queue yield queue.enqueue_job(job) except NoSuchJobError: pass if not migration_job_ids: xmppuser.worker=conf.MACHINEID xmppuser.onMigrationTime='' yield xmppuser.save() migration_job_ids = yield migration_queue.job_ids yield migration_queue.empty() finally: xmppuser.worker = conf.MACHINEID xmppuser.onMigrationTime='' res = yield xmppuser.save() self.log.info('RELOGIN %s. Finished. Data %s. Save result: %s', xmppuser.jid, xmppuser, res)
def initializationFailed(self, reason): if not reason.check(SASLAuthError): return self.onAuthenticationError(reason) current_time = Timer().utcnow() if self._authFailureTime is None: self._authFailureTime = current_time return self.onAuthenticationRenewal(reason) if (current_time - self._authFailureTime).seconds > self.AUTH_TIMEOUT: return self.onAuthenticationError(reason)
def constructor(self): defer.Deferred.debug = conf.DEFERRED_DEBUG self.app = service.Application('KatooApp') self.log = TwistedLogging(self.app) self.service = self.app.getComponent(service.IService, None) self.oldreactorstop = reactor.stop reactor.stop = newreactorstop RedisMixin.setup(conf.REDIS_URL) MongoMixin.setup(conf.MONGO_URL) self.running = True Timer().setServiceParent(self.app)
def get_away(cls): disconnected_time = Timer().utcnow() - timedelta( seconds=conf.XMPP_DISCONNECTION_TIME) return cls.model.find( spec={ '_connected': True, '_away': True, '_lastTimeConnected': { "$lt": disconnected_time } })
def _authd(self, xs): currTime = Timer().utcnow() self._authFailureTime = None self._lastTimeAuth = self._connectedTime = currTime XMPPClient._authd(self, xs)
def connectedTime(self): return 0 if self._connectedTime is None else ( Timer().utcnow() - self._connectedTime).seconds
def lastTimeAuth(self): return 0 if self._lastTimeAuth is None else ( Timer().utcnow() - self._lastTimeAuth).seconds
def notifyWhenAvailable(self): return False if self._notifyWhenAvailable is None else Timer().utcnow( ) <= self._notifyWhenAvailable
def snoozePushTime(self): return False if self._snoozePushTime is None else Timer().utcnow( ) <= self._snoozePushTime