Skip to content

Commit

Permalink
added gig info to email stat for better tracing of issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Oppenheimer authored and Aaron Oppenheimer committed Jun 5, 2024
1 parent 36babfe commit 7db8640
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gig/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def send_emails_from_plans(plans_query, template, dates=None):

# do this as a counter even though any specific call of this will be for a single band.
if contactable.count():
register_sent_emails(contactable.first().gig.band, contactable.count())
register_sent_emails(contactable.first().gig.band, contactable.count(),contactable.first().gig.id)

def send_email_from_gig(gig, template, dates=None):
send_emails_from_plans(gig.member_plans, template, dates)
Expand Down
7 changes: 4 additions & 3 deletions stats/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class Metric(models.Model):
kind = models.IntegerField(
choices=MetricTypes.choices, default=MetricTypes.DAILY)

def register(self, val):
def register(self, val, extra=None):
if self.kind == MetricTypes.ALLTIME:
# for this kind of metric there is only one stat
Stat.objects.lock_for_update().update_or_create(
Stat.objects.update_or_create(
metric=self,
defaults={
"metric":self,
Expand Down Expand Up @@ -67,7 +67,7 @@ def register(self, val):
obj.save(["value"])
elif self.kind == MetricTypes.EVERY:
# just save a stat every time
_ = Stat.objects.create(metric=self, value=val)
_ = Stat.objects.create(metric=self, value=val, extra=extra)

def latest_value(self):
if self.kind == MetricTypes.EVERY:
Expand Down Expand Up @@ -105,6 +105,7 @@ class Stat(models.Model):
BandMetric, related_name="stats", on_delete=models.CASCADE, null=False)
created = models.DateField(auto_now_add=True)
value = models.IntegerField(blank=True, default=0)
extra = models.IntegerField(blank=True, null=True)

def __str__(self):
return "Stat of '{0}' created {1}".format(self.metric, self.created)
6 changes: 3 additions & 3 deletions stats/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def collect_band_stats():
).count()
m.register(gigcount)

def register_sent_emails(band, count):
def register_sent_emails(band, count, gig_id):
""" recieves a collections Counter object of bands """

""" add to the total emails sent by this band """
Expand All @@ -63,8 +63,8 @@ def register_sent_emails(band, count):
defaults={
'name' : 'Number of Emails Sent',
'band' : band,
'kind' : MetricTypes.EVERY
'kind' : MetricTypes.EVERY,
}
)
m.register(count)
m.register(count, gig_id)

0 comments on commit 7db8640

Please sign in to comment.