Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Eventbrite flood of webhooks, log to info #227

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected void processEvent(String eventType, WebhookPayload webhookPayload, Env
CrmCampaign campaign = null;
if (_campaign.isEmpty()) {
EventBriteClient.Event event = eventBriteClient.getEvent("https://www.eventbriteapi.com/v3/events/" + attendee.eventId + "/");
campaign = upsertCrmCampaign(event, crmService);
campaign = upsertCrmCampaign(event, crmService, env);
} else {
campaign = _campaign.get();
}
Expand All @@ -107,7 +107,7 @@ protected void processEvent(String eventType, WebhookPayload webhookPayload, Env
// Skipping event.created entirely, since it's immediately followed up with an event.updated.
case "event.updated", "event.published" -> {
EventBriteClient.Event event = eventBriteClient.getEvent(webhookPayload.apiUrl);
upsertCrmCampaign(event, crmService);
upsertCrmCampaign(event, crmService, env);
}
case "event.unpublished" -> {
EventBriteClient.Event event = eventBriteClient.getEvent(webhookPayload.apiUrl);
Expand Down Expand Up @@ -163,7 +163,7 @@ protected void processNewOrder(EventBriteClient.Order order, CrmService crmServi
Optional<CrmCampaign> campaign = crmService.getCampaignByExternalReference(order.eventId);
if (campaign.isEmpty()) {
EventBriteClient.Event event = env.eventBriteClient().getEvent("https://www.eventbriteapi.com/v3/events/" + order.eventId + "/");
upsertCrmCampaign(event, crmService);
upsertCrmCampaign(event, crmService, env);
}

// attendee can have a partial profile, which could have "Info Requested" as the email/name
Expand Down Expand Up @@ -206,12 +206,16 @@ protected void upsertCrmContact(CrmContact contact, Optional<CrmContact> existin
}
}

protected CrmCampaign upsertCrmCampaign(EventBriteClient.Event event, CrmService crmService) throws Exception {
protected CrmCampaign upsertCrmCampaign(EventBriteClient.Event event, CrmService crmService, Environment env) throws Exception {
CrmCampaign campaign = buildCrmCampaign(event);
Optional<CrmCampaign> existingCampaign = crmService.getCampaignByExternalReference(event.id);

if (existingCampaign.isEmpty()) {
campaign.id = crmService.insertCampaign(campaign);
try {
campaign.id = crmService.insertCampaign(campaign);
} catch (Exception e) {
env.logJobInfo("unable to create new campaign: {}", e.getMessage());
}
} else {
campaign.id = existingCampaign.get().id;
crmService.updateCampaign(campaign);
Expand Down
Loading