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

chore: platform api usage based billing using queue #15085

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

ThyMinimalDev
Copy link
Contributor

What does this PR do?

Usage based billing for platform api using Bull Queue

  • Creating a booking
    • a job is created to increment the usage when the booking will start
  • Canceling a booking
    • cancel the job that was supposed to run to increment usage when booking would start
  • Reschedule
    • cancel the job that was supposed to run to increment usage when booking would start
    • create a new job to increment usage when rescheduled booking will happen

if you are wondering why we don't simply tell stripe to decrement usage, it's simply because stripe does not allow it.

@graphite-app graphite-app bot requested a review from a team May 16, 2024 23:29
Copy link
Contributor

github-actions bot commented May 16, 2024

Thank you for following the naming conventions! 🙏 Feel free to join our discord and post your PR link.

@keithwillcode keithwillcode added core area: core, team members only platform Anything related to our platform plan labels May 16, 2024
@graphite-app graphite-app bot requested a review from a team May 16, 2024 23:30
@dosubot dosubot bot added the billing area: billing, stripe, payments, paypal, get paid label May 16, 2024
Copy link

graphite-app bot commented May 16, 2024

Graphite Automations

"Add foundation team as reviewer" took an action on this PR • (05/16/24)

1 reviewer was added to this PR based on Keith Williams's automation.

"Add platform team as reviewer" took an action on this PR • (05/16/24)

1 reviewer was added to this PR based on Keith Williams's automation.

@dosubot dosubot bot added the bookings area: bookings, availability, timezones, double booking label May 16, 2024
Copy link

socket-security bot commented May 16, 2024

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/is-core-module@2.13.1 None 0 30.2 kB ljharb

View full report↗︎

Copy link

socket-security bot commented May 16, 2024

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report↗︎

Copy link

vercel bot commented May 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ai ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2024 2:01pm
2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview May 30, 2024 2:01pm
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview May 30, 2024 2:01pm

Copy link
Contributor

github-actions bot commented May 16, 2024

📦 Next.js Bundle Analysis for @calcom/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

Copy link

deploysentinel bot commented May 17, 2024

Current Playwright Test Results Summary

✅ 321 Passing - ⚠️ 13 Flaky

Run may still be in progress, this comment will be updated as current testing workflow or job completes...

(Last updated on 05/18/2024 06:12:57am UTC)

Run Details

Running Workflow PR Update on Github Actions

Commit: 2f0fdf0

Started: 05/18/2024 06:10:46am UTC

⚠️ Flakes

📄   apps/web/playwright/booking-seats.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Reschedule for booking with seats If rescheduled/cancelled booking with seats it should display the correct number of seats
Retry 1Initial Attempt
0% (0) 0 / 212 runs
failed over last 7 days
1.89% (4) 4 / 212 runs
flaked over last 7 days

📄   apps/web/playwright/profile.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Update Profile Can update a users email (verification enabled)
Retry 2Retry 1Initial Attempt
38.02% (92) 92 / 242 runs
failed over last 7 days
33.47% (81) 81 / 242 runs
flaked over last 7 days

📄   packages/app-store/routing-forms/playwright/tests/basic.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Routing Forms Seeded Routing Form Test preview should return correct route
Retry 1Initial Attempt
0.91% (2) 2 / 219 runs
failed over last 7 days
31.05% (68) 68 / 219 runs
flaked over last 7 days

📄   apps/web/playwright/event-types.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Event Types tests -- legacy user Different Locations Tests Can remove location from multiple locations that are saved
Retry 1Initial Attempt
4.48% (10) 10 / 223 runs
failed over last 7 days
19.28% (43) 43 / 223 runs
flaked over last 7 days

📄   apps/web/playwright/managedBooking/advancedOptions.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Check advanced options in a managed team event type Check advanced options in a managed team event type without offer seats
Retry 1Initial Attempt
0.45% (1) 1 / 220 run
failed over last 7 days
48.18% (106) 106 / 220 runs
flaked over last 7 days

📄   apps/web/playwright/signup.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Signup Flow Test Email verification sent if enabled
Retry 1Initial Attempt
0.85% (2) 2 / 234 runs
failed over last 7 days
25.64% (60) 60 / 234 runs
flaked over last 7 days

📄   packages/embeds/embed-core/playwright/tests/namespacing.e2e.ts • 4 Flakes

Top 1 Common Error Messages

null

4 Test Cases Affected

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Namespacing Inline Embed Add inline embed using a namespace without reload
Retry 1Initial Attempt
0.46% (1) 1 / 219 run
failed over last 7 days
60.27% (132) 132 / 219 runs
flaked over last 7 days
Namespacing Inline Embed Double install Embed Snippet with inline embed without a namespace(i.e. default namespace)
Retry 1Initial Attempt
0% (0) 0 / 219 runs
failed over last 7 days
63.01% (138) 138 / 219 runs
flaked over last 7 days
Namespacing Inline Embed Double install Embed Snippet with inline embed using a namespace
Retry 1Initial Attempt
0.46% (1) 1 / 219 run
failed over last 7 days
60.27% (132) 132 / 219 runs
flaked over last 7 days
Namespacing Different namespaces can have different init configs
Retry 1Initial Attempt
0% (0) 0 / 217 runs
failed over last 7 days
60.37% (131) 131 / 217 runs
flaked over last 7 days

📄   apps/web/playwright/hash-my-url.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
hash my url generate url hash
Retry 2Retry 1Initial Attempt
5.96% (13) 13 / 218 runs
failed over last 7 days
27.98% (61) 61 / 218 runs
flaked over last 7 days

📄   apps/web/playwright/teams.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Teams - NonOrg -- legacy Can create a booking for Round Robin EventType
Retry 2Retry 1Initial Attempt
7.30% (17) 17 / 233 runs
failed over last 7 days
28.76% (67) 67 / 233 runs
flaked over last 7 days

📄   apps/web/playwright/organization/booking.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Bookings Team Event Can create a booking for Round Robin EventType
Retry 2Retry 1Initial Attempt
7.89% (18) 18 / 228 runs
failed over last 7 days
27.63% (63) 63 / 228 runs
flaked over last 7 days

View Detailed Build Results


Copy link
Contributor

@supalarry supalarry left a comment

Choose a reason for hiding this comment

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

Have refactor suggestions below.

Also, do you think it's possible to add tests to ensure that queue works as expected? It's hard to test this one manually.

packages/features/bookings/lib/handleCancelBooking.ts Outdated Show resolved Hide resolved
apps/api/v2/src/modules/billing/billing.processor.ts Outdated Show resolved Hide resolved
…b.com:calcom/cal.com into chore-platformapi-billing-queue
INCREMENT_JOB,
{
oAuthClientId: clientId,
} satisfies IncrementJobDataType,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can skip using zod since we use satisfies here and this should be the only place we ever call the INCREMENT_JOB

@keithwillcode keithwillcode marked this pull request as draft May 17, 2024 16:39
@keithwillcode
Copy link
Contributor

Putting this back in draft until we have the proper discussion around Bull

@ThyMinimalDev
Copy link
Contributor Author

need to change the logic to increment usage of managed user instead of relying on oauth client id ,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api area: API, enterprise API, access token, OAuth billing area: billing, stripe, payments, paypal, get paid bookings area: bookings, availability, timezones, double booking core area: core, team members only platform Anything related to our platform plan
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants