Skip to content

Commit 77c8c10

Browse files
authored
Merge pull request #186 from sbs2001/cli_batchsize
Add CLI option to specify batch_size for the ImportRunner
2 parents 946ff73 + efe5769 commit 77c8c10

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

vulnerabilities/management/commands/import.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,17 @@ def add_arguments(self, parser):
5151
parser.add_argument('sources', nargs='*',
5252
help='Data sources from which to import')
5353

54+
parser.add_argument(
55+
'--batch_size', help='The batch size to be used for bulk inserting data')
56+
5457
def handle(self, *args, **options):
5558
if options['list']:
5659
self.list_sources()
5760
return
5861

62+
if options['batch_size']:
63+
self.batch_size = options['batch_size']
64+
5965
if options['all']:
6066
self._import_data(Importer.objects.all(), options['cutoff_date'])
6167
return
@@ -94,8 +100,7 @@ def import_data(self, names, cutoff_date):
94100
def _import_data(self, importers, cutoff_date):
95101
for importer in importers:
96102
self.stdout.write(f'Importing data from {importer.name}')
97-
# TODO add cmdline param for batch_size
98-
ImportRunner(importer, 10).run(cutoff_date=cutoff_date)
99-
103+
batch_size = getattr(self, 'batch_size', 10)
104+
ImportRunner(importer, batch_size).run(cutoff_date=cutoff_date)
100105
self.stdout.write(
101106
self.style.SUCCESS(f'Successfully imported data from {importer.name}'))

0 commit comments

Comments
 (0)