Skip to content

Conversation

@andresgutgon
Copy link
Contributor

@andresgutgon andresgutgon commented Dec 9, 2025

What?

We want to send an email with relevant data for the organizations using Latitude. We'll do the processing of this data on monday, 1:00 A.M and it will be sent to be ready on users' inboxes on Monday morning

TODO

  • Implement schedule job (keep commented)
  • Implement individual jobs
  • Implement data fetching for workspace data and memberships data (filter unsubscribed to weekly)
  • In issues if new issues link to those issues. Else link to the live project issues dashboard
  • Add links in projects to live commit and in new issues, use the commit we have.
  • Add info about how to connect logs to production. Point to docs.
  • Add info on how issues can help your latitude projects to improve. Point to the issues dashboard
  • Add info when no annotations present, point to Annotations live commit.
  • QA escalating email batch
  • QA schedule weekly email
  • QA with Mailgun

@andresgutgon andresgutgon force-pushed the feature/weekly-email-scheduled-job branch 2 times, most recently from 6602187 to a8ca59c Compare December 10, 2025 11:51
.selectDistinct({ workspaceId: spans.workspaceId })
.from(spans)
.where(
and(eq(spans.type, SpanType.Prompt), gte(spans.startedAt, fourWeeksAgo)),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Active workspace definition in terms of traces

Copy link
Collaborator

@geclos geclos Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can potentially time out in production, keep an eye on it


// Enqueue individual cleanup job for each free workspace
for (const workspace of freeWorkspaces) {
const { maintenanceQueue } = await queues()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ok? I think it can be shared between iterations

}
}),
)
await mailer.sendInBatches({
Copy link
Contributor Author

@andresgutgon andresgutgon Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I DRYed and now this is how can send emails in batches. Meaning same email template will be sent to all the addressList. The limitation here is that a batch email can not have personalized info by email/user. In the case of this weekly email is fine.

@andresgutgon andresgutgon force-pushed the feature/weekly-email-scheduled-job branch 2 times, most recently from 56e4154 to 960b3f6 Compare December 11, 2025 12:01
@andresgutgon andresgutgon requested a review from geclos December 11, 2025 12:01
@andresgutgon andresgutgon force-pushed the feature/weekly-email-scheduled-job branch from 960b3f6 to b79ae3f Compare December 11, 2025 13:13
We want to send an email with relevant data for the organizations using
Latitude. We'll do the processing of this data on monday 1:00 A.M and it
will be sent to be ready on users' inbox on monday morning
@andresgutgon andresgutgon force-pushed the feature/weekly-email-scheduled-job branch from b79ae3f to 6333616 Compare December 11, 2025 13:16
.action(async ({ parsedInput }) => {
const { workspaceId, emails } = parsedInput

// Parse comma-separated emails if provided
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove ai comments when possible

import { ScoreCell } from './ScoreCell'
import { cn } from '@latitude-data/web-ui/utils'
import { formatCount } from '$/lib/formatCount'
import { formatCount } from '@latitude-data/constants/formatCount'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird that constants exposes a function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But is a really nice method and I want to share it between apps/web and packages/email. Constants is the right place. Constants could have been called in other way. I agree on that.

inArray(issueHistograms.issueId, newIssueIds),
),
)
.as('latestHistogram')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this complexity the n of issues/histograms in a workspace is minuscule

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is getting the latest histogram produced for the issue to get the most recent commit where that issue occurred. I want the commit.uuid to build the URL to point to the right issue details on the right commit in issues dashboard

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you select distinct with a limit? don't know why the window function

.where(inArray(issues.id, newIssueIds))
.orderBy(desc(issues.createdAt))
.limit(10)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having trouble understanding this query with the previous histogram subquery. Couldn't you just fetch the latest histograms by ocurred at ordering and select distinct issue id and then filter by those in this query?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andresgutgon andresgutgon merged commit ba55780 into main Dec 11, 2025
7 checks passed
@andresgutgon andresgutgon deleted the feature/weekly-email-scheduled-job branch December 11, 2025 14:01
@github-actions github-actions bot locked and limited conversation to collaborators Dec 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants