-
Notifications
You must be signed in to change notification settings - Fork 23
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
added retry & timeout fields #371
base: main
Are you sure you want to change the base?
Changes from 2 commits
6df1fe6
6850f50
3095ed2
144b82c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,7 +20,7 @@ import { Scheduler, SchedulerService } from '../handler'; | |||||
import { useTranslator } from '../hooks'; | ||||||
import { ICreateJobModel, IJobParameter, JobsView } from '../model'; | ||||||
import { Scheduler as SchedulerTokens } from '../tokens'; | ||||||
import { NameError } from '../util/job-name-validation'; | ||||||
import { NameError, MaxRetryAttemptsError, MaxRunTimeError, MaxWaitTimeError } from '../util/job-name-validation'; | ||||||
|
||||||
import { caretDownIcon } from '@jupyterlab/ui-components'; | ||||||
|
||||||
|
@@ -191,6 +191,26 @@ export function CreateJob(props: ICreateJobProps): JSX.Element { | |||||
} | ||||||
}; | ||||||
|
||||||
const handleNumericInputChange = (event: ChangeEvent<HTMLInputElement>) => { | ||||||
const target = event.target; | ||||||
|
||||||
const parameterNameIdx = parameterNameMatch(target.name); | ||||||
const parameterValueIdx = parameterValueMatch(target.name); | ||||||
const newParams = props.model.parameters || []; | ||||||
|
||||||
if (parameterNameIdx !== null) { | ||||||
newParams[parameterNameIdx].name = target.value; | ||||||
props.handleModelChange({ ...props.model, parameters: newParams }); | ||||||
} else if (parameterValueIdx !== null) { | ||||||
newParams[parameterValueIdx].value = +target.value; | ||||||
props.handleModelChange({ ...props.model, parameters: newParams }); | ||||||
} else { | ||||||
const value = +target.value; | ||||||
const name = target.name; | ||||||
props.handleModelChange({ ...props.model, [name]: isNaN(value)? target.value: value }); | ||||||
} | ||||||
}; | ||||||
|
||||||
const handleSelectChange = (event: SelectChangeEvent<string>) => { | ||||||
const target = event.target; | ||||||
|
||||||
|
@@ -495,6 +515,57 @@ export function CreateJob(props: ICreateJobProps): JSX.Element { | |||||
environmentList={environmentList} | ||||||
value={props.model.environment} | ||||||
/> | ||||||
<TextField | ||||||
label={trans.__('Maximum Retry Attempts')} | ||||||
variant="outlined" | ||||||
onChange={e => { | ||||||
// Validate name | ||||||
setErrors({ | ||||||
...errors, | ||||||
maxRetryAttempts: MaxRetryAttemptsError(e.target.value, trans) | ||||||
}); | ||||||
handleNumericInputChange(e as ChangeEvent<HTMLInputElement>); | ||||||
}} | ||||||
error={!!errors['maxRetryAttempts']} | ||||||
helperText={errors['maxRetryAttempts'] ?? ''} | ||||||
value={props.model.maxRetryAttempts} | ||||||
id={`${formPrefix}maxRetryAttempts`} | ||||||
name="maxRetryAttempts" | ||||||
/> | ||||||
<TextField | ||||||
label={trans.__('Max Run Time (In Seconds)')} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
"Maximum" was not abbreviated above |
||||||
variant="outlined" | ||||||
onChange={e => { | ||||||
// Validate name | ||||||
setErrors({ | ||||||
...errors, | ||||||
maxRunTime: MaxRunTimeError(e.target.value, trans) | ||||||
}); | ||||||
handleNumericInputChange(e as ChangeEvent<HTMLInputElement>); | ||||||
}} | ||||||
error={!!errors['maxRunTime']} | ||||||
helperText={errors['maxRunTime'] ?? ''} | ||||||
value={props.model.maxRunTime} | ||||||
id={`${formPrefix}maxRunTime`} | ||||||
name="maxRunTime" | ||||||
/> | ||||||
<TextField | ||||||
label={trans.__('Max Wait Time (In Seconds)')} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
variant="outlined" | ||||||
onChange={e => { | ||||||
// Validate name | ||||||
setErrors({ | ||||||
...errors, | ||||||
maxWaitTime: MaxWaitTimeError(e.target.value, trans) | ||||||
}); | ||||||
handleNumericInputChange(e as ChangeEvent<HTMLInputElement>); | ||||||
}} | ||||||
error={!!errors['maxWaitTime']} | ||||||
helperText={errors['maxWaitTime'] ?? ''} | ||||||
value={props.model.maxWaitTime} | ||||||
id={`${formPrefix}maxWaitTime`} | ||||||
name="maxWaitTime" | ||||||
/> | ||||||
<OutputFormatPicker | ||||||
label={trans.__('Output formats')} | ||||||
name="outputFormat" | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ import { TranslationBundle } from '@jupyterlab/translation'; | |||||
const jobNameRegex = /^[a-zA-Z0-9._][a-zA-Z0-9._ -]{0,62}$/; | ||||||
const invalidFirstCharRegex = /^[^a-zA-Z0-9._]/; | ||||||
const invalidCharRegex = /[^a-zA-Z0-9._ -]/g; | ||||||
const validIntegerRregex = /^[+]?[1-9]\d*$/; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't see a reason why zero-prefixed integers like |
||||||
const maxLength = 63; | ||||||
|
||||||
export function NameIsValid(name: string): boolean { | ||||||
|
@@ -64,3 +65,63 @@ export function NameError(name: string, trans: TranslationBundle): string { | |||||
'Name must contain only letters, numbers, spaces, periods, hyphens, and underscores' | ||||||
); | ||||||
} | ||||||
|
||||||
export function MaxRetryAttemptsError(maxRetryAttempts: string, trans: TranslationBundle): string { | ||||||
// Check for blank | ||||||
if (maxRetryAttempts === '') { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be an optional parameter, since existing users editing job definitions will not have these values set. |
||||||
return trans.__('You must specify max retry attempts'); | ||||||
} | ||||||
|
||||||
if (!validIntegerRregex.test(maxRetryAttempts)) { | ||||||
return trans.__( | ||||||
'Max retry attempts must be an integer' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Explain the acceptable range in the error |
||||||
); | ||||||
} | ||||||
const integerValue = +maxRetryAttempts | ||||||
// Check for length. | ||||||
if (integerValue < 1 || integerValue > 30) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use symbolic constants to indicate the minimum and maximum acceptable values. Why isn't 0 an acceptable value? It would fit if I wanted a job to be tried only once, and never retried if it fails. |
||||||
return trans.__('Max retry attempts must be between 1 and 30'); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Explain the acceptable range in the error |
||||||
} | ||||||
|
||||||
return ''; | ||||||
} | ||||||
|
||||||
export function MaxRunTimeError(maxRunTime: string, trans: TranslationBundle): string { | ||||||
// Check for blank | ||||||
if (maxRunTime === '') { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be an optional parameter, since existing users editing job definitions will not have these values set. |
||||||
return trans.__('You must specify max run time'); | ||||||
} | ||||||
|
||||||
if (!validIntegerRregex.test(maxRunTime)) { | ||||||
return trans.__( | ||||||
'Max run time must be an integer' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
); | ||||||
} | ||||||
const integerValue = +maxRunTime | ||||||
// Check for length. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix or delete this comment |
||||||
if (integerValue < 1) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a symbolic constant |
||||||
return trans.__('Max run time must be greater than 1'); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
return ''; | ||||||
} | ||||||
|
||||||
export function MaxWaitTimeError(maxWaitTime: string, trans: TranslationBundle): string { | ||||||
// Check for blank | ||||||
if (maxWaitTime === '') { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be an optional parameter, since existing users editing job definitions will not have these values set. |
||||||
return trans.__('You must specify max run time'); | ||||||
} | ||||||
|
||||||
if (!validIntegerRregex.test(maxWaitTime)) { | ||||||
return trans.__( | ||||||
'Max wait time must be an integer' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
); | ||||||
} | ||||||
const integerValue = +maxWaitTime | ||||||
// Check for length. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix or delete this comment |
||||||
if (integerValue < 1) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a symbolic constant |
||||||
return trans.__('Max wait time must be greater than 1'); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
return ''; | ||||||
} |
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.
This code is copied from the code for setting parameters, which have user-provided names and values. Your change is intended to add input fields with only user-provided values.