class SMSTransport(Worker): """ The SMSTransport for Foneworx """ @inlineCallbacks def startWorker(self): log.msg("Starting the SMSTransport") self.last_polled_at = None username = self.config.pop('username') password = self.config.pop('password') host = self.config.pop("host") port = self.config.pop("port") self.client = Client(username, password, connection=TwistedConnection( host, port, )) self.publisher = yield self.start_publisher(FoneworxPublisher) self.consumer = yield self.start_consumer(FoneworxConsumer) reactor.callLater(0, self.send_and_receive) @inlineCallbacks def send_and_receive(self): log.msg("Sending and receiving") new_messages = self.receive(self.last_polled_at) self.last_polled_at = datetime.now() # this is inaccurate for inbound in new_messages: self.publisher.publish_json(inboud) self.delete(inboud) for outbound in self.consumer.queue: sent_messages = self.send(**outbound) @inlineCallbacks def send(self, msisdn, message): sent_messages = yield self.client.send_messages([ { 'msisdn': msisdn, 'message': message } ]) returnValue(sent_messages) @inlineCallbacks def receive(self, *args, **kwargs): new_messages = yield self.client.new_messages(*args, **kwargs) returnValue(new_messages) @inlineCallbacks def delete(self, sms): deleted = yield self.client.delete_message(sms['sms_id']) def stopWorker(self): log.msg("Stopping the SMSTransport")
def startWorker(self): log.msg("Starting the SMSTransport") self.last_polled_at = None username = self.config.pop('username') password = self.config.pop('password') host = self.config.pop("host") port = self.config.pop("port") self.client = Client(username, password, connection=TwistedConnection( host, port, )) self.publisher = yield self.start_publisher(FoneworxPublisher) self.consumer = yield self.start_consumer(FoneworxConsumer) reactor.callLater(0, self.send_and_receive)