-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat: Add charge
method to the run client for "pay per event"
#613
Conversation
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"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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