Skip to content

Commit

Permalink
Small AddJobs improvements
Browse files Browse the repository at this point in the history
* Try to guess which runtime environment will be used by file extension.
* Add a little cron syntax help blurb and squish some margins so it mostly fits in the dialog.
* Fix a couple of typos.
* Make papermill emit stdout and stderr logs.
* TODO: that papermill output should be named like `input_file-cron-out.ipynb` so they don't collide.
  • Loading branch information
mitch-wallaroo committed Sep 20, 2022
1 parent 4ea42c5 commit 912fcf1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
41 changes: 33 additions & 8 deletions src/AddJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ class Component extends React.Component {

triggerInitialEnvSelection(){
const input = document.getElementById("run_environment");
const event = new Event("change", { bubbles: true });
const event = new CustomEvent("change", { bubbles: true, detail: { initializing: true }});
input.dispatchEvent(event);

}

scheduleChange(event) {
Expand Down Expand Up @@ -84,7 +83,25 @@ class Component extends React.Component {

runEnvironmentChange(event) {
if(event.target.name === "run_environment"){
const runEnvironment = event.target.value
let runEnvironment = event.target.value

// Set a sensible default but user can override with the selector.
if (event.nativeEvent.detail && event.nativeEvent.detail.initializing) {
let file_extension = this.props.script.split('.').reverse()[0];
switch(file_extension) {
case "sh":
runEnvironment = "bash";
break;
case "py":
runEnvironment = "python";
break;
case "ipynb":
runEnvironment = "papermill";
break;
default:
}
console.log("re2: %o", runEnvironment)
}

let updatedCommand = ''

Expand All @@ -97,7 +114,8 @@ class Component extends React.Component {
updatedCommand = `python ${this.props.script_path}`;
break;
case "papermill":
updatedCommand = `papermill ${this.props.script_path} /dev/null`;
let var base = path.basename(this.props.script, '.ipynb');
updatedCommand = `papermill --stdout-file ${base}-out.log --stderr-file ${base}-err.log ${this.props.script_path} /dev/null`;
break;
case "custom":
updatedCommand = `[CUSTOM_RUN_ENVIRONMENT_GOES_HERE] ${this.props.script_path}`;
Expand Down Expand Up @@ -214,6 +232,13 @@ class Component extends React.Component {
<div>
<input type="text" name="schedule" value={this.state.schedule} onChange={this.scheduleChange} />
</div>
<ul style={{"margin":"0"}}>
<li> minute (0 - 59)</li>
<li> hour (0 - 23)</li>
<li> day of month (1 - 31)</li>
<li> month (1 - 12) OR jan,feb,mar,apr ...</li>
<li> day of week (0 - 6) (Sunday=0 or 7) or sun,mon,tue,wed,thu,fri,sat</li>
</ul>
</div>

<div style={{"display":"flex","flexDirection":"row", "padding":"10px"}}>
Expand All @@ -228,16 +253,16 @@ class Component extends React.Component {
:
(
<div>
<span style={{"color":"red"}}>Invalid chron syntax!</span>
<span style={{"color":"red"}}>Invalid cron syntax!</span>
</div>
)
}

</div>

{this.state.is_schedule_valid &&
<div style={{"display":"flex","flexDirection":"row", "padding":"10px"}}>
<ul>
<div style={{"display":"flex","flexDirection":"row", "padding":"0px"}}>
<ul style={{"margin":"0"}}>

{this.state.schedule_examples.map((example, i) =>
<li key={i}>{example}</li>
Expand Down Expand Up @@ -280,4 +305,4 @@ export class AddJob extends ReactWidget {
render() {
return <Component script={this.script} script_path={this.script_path}/>;
}
}
}
4 changes: 2 additions & 2 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const extension = {
// Add command for scheduling a job
app.commands.addCommand('jupyterlab_scheduler/add-job:open', {
label: 'Schedule',
caption: "Schedule Recurring Exectuion of File",
caption: "Schedule Recurring Execution of File",
icon: runIcon,
execute: () => {

Expand All @@ -98,4 +98,4 @@ const extension = {
}
};

export default extension;
export default extension;

0 comments on commit 912fcf1

Please sign in to comment.