feat: Add charge method to the run client for "pay per event"#304
Conversation
Co-authored-by: Vlada Dusek <v.dusek96@gmail.com>
Co-authored-by: Vlada Dusek <v.dusek96@gmail.com>
|
@vdusek the URL is a best-effort guess of what it will be when it's added to docs based on apify/apify-client-js#613 (comment) When the docs are created, I added a request to check of these links. Let's leave those issues open until then so we don't forget https://github.com/apify/apify-core/issues/18591#issuecomment-2516852353 |
fnesveda
left a comment
There was a problem hiding this comment.
One note about the idempotency key
| url=self._url('charge'), | ||
| method='POST', | ||
| headers={ | ||
| 'idempotency-key': idempotency_key or f'{self.resource_id}-{event_name}-{int(time.time() * 1000)}', |
There was a problem hiding this comment.
What if someone tries to charge for two occurences of one event twice in the same millisecond? Then the idempotency key will be the same and one charge will get ignored. Some unique key is needed here, I think a random string would be enough.
There's a crypto_random_object_id implementation in Crawlee for Python, perhaps we could move it to apify-shared-python and use it here.
There was a problem hiding this comment.
I took the idempotency key generation from https://github.com/apify-store/contact-info/blob/master/code/src/charging_manager.ts but it could be specific to their actors 🤔 I can move crypto_random_object_id 👍
Resolves https://github.com/apify/apify-core/issues/18593 by adding the charge endpoint to the run client.
Issue to add docs URL #305