def handle(self, *args, **options):
# Setup logger with levels and path
log_path = os.path.join(options['log'], 'riverscope', __name__ + '_log.txt')
if options['debug']:
LOG.set_print_handler_level(logging.DEBUG)
LOG.set_file_handler(log_path, logging.DEBUG)
else:
LOG.set_print_handler_level(logging.INFO)
LOG.set_file_handler(log_path, logging.DEBUG)
time_start = utils.start_timer()
pool = ThreadPool(100)
# TODO http://stackoverflow.com/questions/2632520/what-is-the-fastest-way-to-send-100-000-http-requests-in-python
results = pool.map(get_readings, zip(Stations.objects.all(), repeat(options['lastn'])))
clean_results = list(filter(None, results))
station_readings = [s for sl in clean_results for s in sl]
with transaction.atomic():
StationReadings.objects.all().delete()
StationReadings.objects.bulk_create(station_readings)
time_diff = utils.end_timer(time_start)
LOG.info('Added {} readings in {}'.format(len(station_readings), time_diff))
评论列表
文章目录