-
Notifications
You must be signed in to change notification settings - Fork 54
feat: respect input schema defaults in Actor.getInput()
#409
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
base: master
Are you sure you want to change the base?
Conversation
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.
Few nits, but looks alright to me otherwise, thank you!
return null; | ||
} | ||
|
||
export const readInputSchema = (): Dictionary | null => { |
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.
nit: can we make all of them (readJSONIfExists
, readInputSchema
, getDefaultsFromInputSchema
) function
(or make all of them const
arrow function)?
|
||
export const readInputSchema = (): Dictionary | null => { | ||
const localConfig = readJSONIfExists( | ||
join(process.cwd(), ACTOR_SPECIFICATION_FOLDER, LOCAL_CONFIG_NAME), |
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.
process.cwd()
will likely break if the Dockerfile entry point is not npm (--prefix=app/) start
, but e.g. node app/main.js
But I'm not sure how else we would refer to these files 🤔 I guess it's okay to live with this, especially since on Platform, we load this via API.
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 only gave it a quick look, but it looks like we don't copy the .actor
directory in our Dockerfiles anyway, so for the "build a Docker image and run it outside of the platform" use case, the answer to "But I'm not sure how else we would refer to these files" is probably "tough luck lol" 🤷
But if we add a nice error log when there's not input schema to be found, yeah, we can live with that.
.build(env.actorBuildId) | ||
.get(); | ||
|
||
inputSchema = buildData?.actorDefinition?.input; |
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 would at least log an error if this is not present in the response.
inputSchema = buildData?.actorDefinition?.input; | ||
} else { | ||
// On local, we can get the input schema from the local config | ||
inputSchema = readInputSchema(); |
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.
It'd also be nice to log something if no input schema is found.
|
||
export const readInputSchema = (): Dictionary | null => { | ||
const localConfig = readJSONIfExists( | ||
join(process.cwd(), ACTOR_SPECIFICATION_FOLDER, LOCAL_CONFIG_NAME), |
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 only gave it a quick look, but it looks like we don't copy the .actor
directory in our Dockerfiles anyway, so for the "build a Docker image and run it outside of the platform" use case, the answer to "But I'm not sure how else we would refer to these files" is probably "tough luck lol" 🤷
But if we add a nice error log when there's not input schema to be found, yeah, we can live with that.
Actor.getInput()
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.
few comments from my end
); | ||
} | ||
|
||
private async insertDefaultsFromInputSchema<T extends Dictionary>( |
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.
infer
seems like a better word here
private async insertDefaultsFromInputSchema<T extends Dictionary>( | |
private async inferDefaultsFromInputSchema<T extends Dictionary>( |
@@ -0,0 +1,70 @@ | |||
// TODO: v0, move all this logic from here and apify-cli to input_schema module |
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'd rather see an issue instead of a TODO in code, TODOs always rot in there.
private async insertDefaultsFromInputSchema<T extends Dictionary>( | ||
input: T, | ||
): Promise<T> { | ||
// TODO: v0, move all this logic from here and apify-cli to input_schema module |
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 here
let inputSchema: Dictionary | undefined | null; | ||
|
||
// On platform, we can get the input schema from the build data | ||
if (this.isAtHome() && env.actorBuildId) { |
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.
why do we even need this? this change was only supposed to be dealing with the local development, on platform you always get the whole input from the API
const DEFAULT_INPUT_SCHEMA_PATHS = [ | ||
['.actor', 'INPUT_SCHEMA.json'], | ||
['INPUT_SCHEMA.json'], | ||
['.actor', 'input_schema.json'], | ||
['input_schema.json'], | ||
]; |
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.
the name of the input schema file is configurable via .actor.json
, ideally we'd get it from there
@vladfrangu there are some unresolved comments from others too, I'd like to ship next SDK soon, including this PR, let's try to resolve them asap |
Way too overdue, closes #287