make_sample_transactions.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from django.utils import timezone
  2. from glitchtip.base_commands import MakeSampleCommand
  3. from performance.models import TransactionEvent
  4. from performance.test_data import generate_fake_transaction_event
  5. from projects.models import TransactionEventProjectHourlyStatistic
  6. class Command(MakeSampleCommand):
  7. help = (
  8. "Create a large number of transaction events for dev and demonstration purposes"
  9. )
  10. def handle(self, *args, **options):
  11. super().handle(*args, **options)
  12. quantity = options["quantity"]
  13. batch_size = self.batch_size
  14. if quantity < batch_size:
  15. batches = 1
  16. else:
  17. batches = quantity // batch_size
  18. for _ in range(batches):
  19. if quantity < batch_size:
  20. batch_size = quantity
  21. event_list = []
  22. for _ in range(batch_size):
  23. event = generate_fake_transaction_event(self.project, timezone.now())
  24. event_list.append(event)
  25. TransactionEvent.objects.bulk_create(event_list)
  26. quantity -= batch_size
  27. self.progress_tick()
  28. TransactionEventProjectHourlyStatistic.update(self.project.pk, timezone.now())
  29. self.success_message(
  30. 'Successfully created "%s" transaction events' % options["quantity"]
  31. )