def create_long_connection(self): if not len(Connector.get_online_protocol('ConnectionPlatform')): print u"未连接.............." reactor.connectTCP(self.host, self.port, self.long_connection) print u'正在重连.............' self.status = False self.instance = None else: if self.status is False: self.instance = Connector.get_online_protocol( 'ConnectionPlatform')[0] self.status = True self.instance.transport.write(json.dumps(self.pack_data())) self.instance.work = None print u'已发送数据.............' else: if self.instance.work: self.instance.work['schedule'] = 0.5 self.instance.work['entry_time'] = datetime.datetime.now( ).strftime('%Y-%m-%d %H:%M:%S') self.instance.work['status'] = 'work' print self.instance.work['task_id'], "success" self.instance.transport.write( json.dumps( scrapy_base_html.collect_num_page( "https://mrmichaelchen.github.io/2018/05/23/Cisco-Orders/", 3))) reactor.callLater(1, self.create_long_connection)
def create_long_connection(self): """建立长连接""" if not len(Connector.get_online_protocol('ConnectionPlatform')): print u"未连接........................" reactor.connectTCP(self.host, self.port, self.long_connection) print u"正在重连........................" self.status = False self.instance = None else: if self.status is False: self.instance = Connector.get_online_protocol( 'ConnectionPlatform')[0] self.status = True self.instance.transport.write(json.dumps(self.pack_data())) print u"已发送采集的到的数据....................." else: work_status = list() for work in self.instance.work: work['schedule'] = 0.5 work['entry_time'] = datetime.datetime.now().strftime( '%Y-%m-%d %H:%M:%S') work['status'] = 'work' work['result'] = "<a>正在生成</a>" work['cur_weight'] = self.instance.cur_weight work_status.append(work) if work_status: self.instance.transport.write(json.dumps(work_status)) reactor.callLater(1, self.create_long_connection) # 一直尝试在连接
def create_long_connection(self): """建立长连接""" if not len(Connector.get_online_protocol('ConnectionPlatform')): print u"未连接........................" reactor.connectTCP(self.host, self.port, self.long_connection) print u"正在重连........................" self.status = False self.instance = None else: if self.status is False: self.instance = Connector.get_online_protocol( 'ConnectionPlatform')[0] self.status = True self.instance.transport.write(json.dumps(self.pack_data())) self.instance.work = None print u"已发送采集的到的数据....................." else: if self.instance.work: self.instance.work['schedule'] = 0.5 self.instance.work['entry_time'] = datetime.datetime.now( ).strftime('%Y-%m-%d %H:%M:%S') self.instance.work['status'] = 'work' print self.instance.work['task_id'], "success" self.instance.transport.write( json.dumps(self.instance.work)) reactor.callLater(1, self.create_long_connection) # 一直尝试在连接
def create_long_connection(self): """建立长连接""" if not len(Connector.get_online_protocol('ConnectionPlatform')): print u"未连接........................" reactor.connectTCP(self.host, self.port, self.long_connection) print u"正在重连........................" else: Connector.get_online_protocol('ConnectionPlatform')[0].transport.write(json.dumps(self.pack_data())) print u"已发送采集的到的数据....................." reactor.callLater(1, self.create_long_connection) # 一直尝试在连接
def create_long_connection(self): """建立长连接""" if not len(Connector.get_online_protocol('ConnectionPlatform')): print u"未连接........................" reactor.connectTCP(self.host, self.port, self.long_connection) print u"正在重连........................" self.instance = None else: reactor.callLater(1, self.pack_job_info) self.instance = Connector.get_online_protocol( 'ConnectionPlatform')[0] self.instance.transport.write(json.dumps(self.pack_data())) print u"已发送心跳包....................." reactor.callLater(1, self.create_long_connection) # 一直尝试在连接
def create_long_connection(self): """建立长连接""" if not len(Connector.get_online_protocol('ConnectionPlatform')): print u"未连接........................" reactor.connectTCP(self.host, self.port, self.long_connection) print u"正在重连........................" else:
self.long_connection = ConnectionFactory('ConnectionPlatform', ConnectionProtocol) self.long_connection.onlineProtocol = Connector self.host = host self.port = port def create_long_connection(self): """建立长连接""" if not len(Connector.get_online_protocol('ConnectionPlatform')): print u"未连接........................" reactor.connectTCP(self.host, self.port, self.long_connection) print u"正在重连........................" else: <<<<<<< HEAD Connector.get_online_protocol('ConnectionPlatform')[0].transport.write(self.pack_data()) print u"已发送采集的到的数据 ....................." ======= Connector.get_online_protocol('ConnectionPlatform')[0].transport.write(json.dumps(self.pack_data())) print u"已发送采集的到的数据....................." >>>>>>> 9d5b2532604be72831385144fc45a0fcbf2d3cf4 reactor.callLater(1, self.create_long_connection) # 一直尝试在连接 @staticmethod def pack_data(): info = dict() info["id"] = '2' info["entry_time"] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') <<<<<<< HEAD