Skip to content

Commit 1015a51

Browse files
committed
Only trigger notification for code cells
1 parent e9f0d81 commit 1015a51

File tree

1 file changed

+50
-49
lines changed

1 file changed

+50
-49
lines changed

src/index.ts

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,25 @@ function triggerNotification(
6767
error: KernelError | null
6868
) {
6969
const { startTime, endTime, index: cellIndex } = executionMetadata;
70-
const codeCell = cell.model.type === 'code';
71-
const nonEmptyCell = cell.model.value.text.length > 0;
72-
if (codeCell && nonEmptyCell) {
73-
const codeCellModel = cell.model as ICodeCellModel;
74-
const cellDuration = moment.utc(moment(endTime).diff(startTime)).format("HH:mm:ss");
75-
const diffSeconds = moment.duration(cellDuration).asSeconds();
76-
if (diffSeconds >= minimumCellExecutionTime) {
77-
const cellNumber =
78-
cellNumberType === 'cell_index'
79-
? cellIndex
80-
: codeCellModel.executionCount;
81-
const notebookName = notebook.title.label.replace(/\.[^/.]+$/, '');
82-
displayNotification(
83-
cellDuration,
84-
cellNumber,
85-
notebookName,
86-
reportCellNumber,
87-
reportCellExecutionTime,
88-
failedExecution,
89-
error
90-
);
91-
}
70+
const codeCellModel = cell.model as ICodeCellModel;
71+
const cellDuration = moment.utc(moment(endTime).diff(startTime)).format("HH:mm:ss");
72+
const diffSeconds = moment.duration(cellDuration).asSeconds();
73+
console.log(cellDuration, diffSeconds);
74+
if (diffSeconds >= minimumCellExecutionTime) {
75+
const cellNumber =
76+
cellNumberType === 'cell_index'
77+
? cellIndex
78+
: codeCellModel.executionCount;
79+
const notebookName = notebook.title.label.replace(/\.[^/.]+$/, '');
80+
displayNotification(
81+
cellDuration,
82+
cellNumber,
83+
notebookName,
84+
reportCellNumber,
85+
reportCellExecutionTime,
86+
failedExecution,
87+
error
88+
);
9289
}
9390
}
9491

@@ -143,35 +140,39 @@ const extension: JupyterFrontEndPlugin<void> = {
143140
if (enabled) {
144141
const cellEndTime = new Date();
145142
const { cell, notebook, success, error } = args;
146-
const cellId = cell.model.id;
147-
const notebookId = notebook.id;
148-
const cellExecutionMetadata = cellExecutionMetadataTable.get(cellId);
149-
const scheduledTime = cellExecutionMetadata.scheduledTime;
150-
// Get the cell's execution scheduled time if the recent notebook execution state doesn't exist.
151-
// This happens commonly for first time notebook executions or notebooks that haven't been executed for a while.
152-
const recentExecutedCellTime =
153-
recentNotebookExecutionTimes.get(notebookId) || scheduledTime;
143+
const codeCell = cell.model.type === 'code';
144+
const nonEmptyCell = cell.model.value.text.length > 0;
145+
if (codeCell && nonEmptyCell) {
146+
const cellId = cell.model.id;
147+
const notebookId = notebook.id;
148+
const cellExecutionMetadata = cellExecutionMetadataTable.get(cellId);
149+
const scheduledTime = cellExecutionMetadata.scheduledTime;
150+
// Get the cell's execution scheduled time if the recent notebook execution state doesn't exist.
151+
// This happens commonly for first time notebook executions or notebooks that haven't been executed for a while.
152+
const recentExecutedCellTime =
153+
recentNotebookExecutionTimes.get(notebookId) || scheduledTime;
154154

155-
// Multiple cells can be scheduled at the same time, and the schedule time doesn't necessarily equate to the actual start time.
156-
// If another cell has been executed more recently than the current cell's scheduled time, treat the recent execution as the cell's start time.
157-
cellExecutionMetadata.startTime =
158-
scheduledTime >= recentExecutedCellTime
159-
? scheduledTime
160-
: recentExecutedCellTime;
161-
cellExecutionMetadata.endTime = cellEndTime;
162-
recentNotebookExecutionTimes.set(notebookId, cellEndTime);
155+
// Multiple cells can be scheduled at the same time, and the schedule time doesn't necessarily equate to the actual start time.
156+
// If another cell has been executed more recently than the current cell's scheduled time, treat the recent execution as the cell's start time.
157+
cellExecutionMetadata.startTime =
158+
scheduledTime >= recentExecutedCellTime
159+
? scheduledTime
160+
: recentExecutedCellTime;
161+
cellExecutionMetadata.endTime = cellEndTime;
162+
recentNotebookExecutionTimes.set(notebookId, cellEndTime);
163163

164-
triggerNotification(
165-
cell,
166-
notebook,
167-
cellExecutionMetadata,
168-
minimumCellExecutionTime,
169-
reportCellNumber,
170-
reportCellExecutionTime,
171-
cellNumberType,
172-
!success,
173-
error
174-
);
164+
triggerNotification(
165+
cell,
166+
notebook,
167+
cellExecutionMetadata,
168+
minimumCellExecutionTime,
169+
reportCellNumber,
170+
reportCellExecutionTime,
171+
cellNumberType,
172+
!success,
173+
error
174+
);
175+
}
175176
}
176177
});
177178
}

0 commit comments

Comments
 (0)