def load(args, tunnel_=False): """Start recording http requests.""" if Bullet.count(): if args.force: Bullet.remove_all() elif args.append: # Proper initialization of main clock. try: latest = Bullet.get_latest() offset = latest.time + 100 except NotFound: offset = 0 clock = MilisecondsClock(offset=offset) Clock.initialize(clock) else: print( "There are already records in database, use '--force' (Luke) " "to erase them, and start new recording, or '--append' " "to continue from 100 miliseconds after last recorded " "request.") exit(0) print('Started listening at port "{}"'.format(settings.config['port'])) app = tornado.web.Application( [(r'/.*', RecordHandler, {'tunnel': tunnel_})]) app.listen(settings.config['port']) loop = tornado.ioloop.IOLoop.instance() loop.start()
def fire(): """Send recorded requests to target address.""" loop = tornado.ioloop.IOLoop.instance() for item in Bullet.get_all_chronologically(): func = partial(send, item.id) last_time = item.time loop.add_timeout(datetime.timedelta(0, 0, 0, item.time), func) def stop_loop(): loop.stop() loop.add_timeout(datetime.timedelta(0, 0, 0, last_time + 100), stop_loop) loop.start()