feat: Add charge method to the run client for "pay per event"#613
feat: Add charge method to the run client for "pay per event"#613
charge method to the run client for "pay per event"#613Conversation
charge method to the run client for "pay per result"
charge method to the run client for "pay per result"charge method to the run client for "pay per event"
B4nan
left a comment
There was a problem hiding this comment.
you can ignore the failing docs build, its not detecting the links inside parens correctly
src/resource_clients/run.ts
Outdated
| * TODO: docs url | ||
| * https://github.com/apify/apify-client-js/issues/614 |
There was a problem hiding this comment.
can we add the URL here right ahead? even if it doesn't exist yet, feels better than publishing with a TODO
There was a problem hiding this comment.
I don't have the URL. I'll ask Mat'o what's the status on the endpoint docs 👍
There was a problem hiding this comment.
I am rather sure we can guess it before it exists, its just another endpoint, the URLs for them are not random.
| /** | ||
| * https://docs.apify.com/api/v2#/reference/actor-runs/charge-run/charge-run | ||
| */ | ||
| async charge(options: RunChargeOptions): Promise<ApifyResponse<Record<string, never>>> { |
There was a problem hiding this comment.
Out of curiosity - what's the expected return type of this method? I see that most of the RunClient methods return ActorRun object (which reflects the changes made by the call).
Is this return type (ApifyResponse<Record<string, never>>) a temporary thing before we figure out the actual API response shape, or is this the final thing?
There was a problem hiding this comment.
We discussed this in person. The endpoint uses a memorized version of the run from the database for performance reasons, as the run's pricing model cannot change during the run. Therefore we cannot return the modified run object and the only important output is the response status code.
fnesveda
left a comment
There was a problem hiding this comment.
One problem copied over from the Python client review
src/resource_clients/run.ts
Outdated
| })); | ||
|
|
||
| const count = options.count ?? 1; | ||
| const idempotencyKey = options.idempotencyKey ?? `${this.id}-${options.eventName}-${Date.now()}`; |
There was a problem hiding this comment.
Same note here as in the Python client, the idempotency key has to be a unique string. This way, if someone charged for two occurences of the same event in the same millisecond, only one of the charges would go through.
Resolves https://github.com/apify/apify-core/issues/18592 by adding the PPE charge endpoint to JS client.
The idempotency key creation was taken from an actor by the store team.
Issue to add docs URL #614