Skip to content

feat(crons): Add interface for heartbeat checkin #9706

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

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/src/server-runtime-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class ServerRuntimeClient<
* to create a monitor automatically when sending a check in.
*/
public captureCheckIn(checkIn: CheckIn, monitorConfig?: MonitorConfig, scope?: Scope): string {
const id = checkIn.status !== 'in_progress' && checkIn.checkInId ? checkIn.checkInId : uuid4();
const id = 'checkInId' in checkIn && checkIn.checkInId ? checkIn.checkInId : uuid4();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkIn.hasOwnProperty('checkInId') might resolve into smaller footprint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundle size wise in would be smaller. If you mean performance, I don't know if we should care. I'd assume the engines do their best in any case. This is not the hottest of hot paths and I don't have benchmarks or any documentation indicators what is faster so 🤷

if (!this._isEnabled()) {
DEBUG_BUILD && logger.warn('SDK not enabled, will not capture checkin.');
return id;
Expand All @@ -164,7 +164,7 @@ export class ServerRuntimeClient<
environment,
};

if (checkIn.status !== 'in_progress') {
if ('duration' in checkIn) {
serializedCheckIn.duration = checkIn.duration;
}

Expand Down
9 changes: 8 additions & 1 deletion packages/types/src/checkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export interface SerializedCheckIn {
};
}

export interface HeartbeatCheckIn {
// The distinct slug of the monitor.
monitorSlug: SerializedCheckIn['monitor_slug'];
// The status of the check-in.
status: 'ok' | 'error';
}

export interface InProgressCheckIn {
// The distinct slug of the monitor.
monitorSlug: SerializedCheckIn['monitor_slug'];
Expand All @@ -61,7 +68,7 @@ export interface FinishedCheckIn {
duration?: SerializedCheckIn['duration'];
}

export type CheckIn = InProgressCheckIn | FinishedCheckIn;
export type CheckIn = HeartbeatCheckIn | InProgressCheckIn | FinishedCheckIn;

type SerializedMonitorConfig = NonNullable<SerializedCheckIn['monitor_config']>;

Expand Down