Skip to content

Commit

Permalink
fix: remove unused alarms, documented format in #35
Browse files Browse the repository at this point in the history
  • Loading branch information
whoabuddy committed Dec 20, 2024
1 parent 7c1b846 commit eccc566
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 91 deletions.
16 changes: 1 addition & 15 deletions src/auth/auth-do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,7 @@ export class AuthDO extends DurableObject<Env> {
this.ALARM_INTERVAL_MS = config.ALARM_INTERVAL_MS;

// Set up alarm to run at configured interval
ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}

async alarm(): Promise<void> {
try {
console.log(`AuthDO: alarm activated`);
} catch (error) {
console.error(`AuthDO: alarm execution failed: ${error instanceof Error ? error.message : String(error)}`);
} finally {
// Always schedule next alarm if one isn't set
const currentAlarm = await this.ctx.storage.getAlarm();
if (currentAlarm === null) {
this.ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}
}
// ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}

async fetch(request: Request): Promise<Response> {
Expand Down
16 changes: 1 addition & 15 deletions src/cdn/cdn-do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,7 @@ export class CdnDO extends DurableObject<Env> {
this.ALARM_INTERVAL_MS = config.ALARM_INTERVAL_MS;

// Set up alarm to run at configured interval
ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}

async alarm(): Promise<void> {
try {
console.log(`CdnDO: alarm activated`);
} catch (error) {
console.error(`CdnDO: alarm execution failed: ${error instanceof Error ? error.message : String(error)}`);
} finally {
// Always schedule next alarm if one isn't set
const currentAlarm = await this.ctx.storage.getAlarm();
if (currentAlarm === null) {
this.ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}
}
// ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}

async fetch(request: Request): Promise<Response> {
Expand Down
16 changes: 1 addition & 15 deletions src/context/context-do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,7 @@ export class ContextDO extends DurableObject<Env> {
this.ALARM_INTERVAL_MS = config.ALARM_INTERVAL_MS;

// Set up alarm to run at configured interval
ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}

async alarm(): Promise<void> {
try {
console.log(`ContextDO: alarm activated`);
} catch (error) {
console.error(`ContextDO: alarm execution failed: ${error instanceof Error ? error.message : String(error)}`);
} finally {
// Always schedule next alarm if one isn't set
const currentAlarm = await this.ctx.storage.getAlarm();
if (currentAlarm === null) {
this.ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}
}
// ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}

async fetch(request: Request): Promise<Response> {
Expand Down
16 changes: 1 addition & 15 deletions src/database/database-do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,7 @@ export class DatabaseDO extends DurableObject<Env> {
this.ALARM_INTERVAL_MS = config.ALARM_INTERVAL_MS;

// Set up alarm to run at configured interval
ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}

async alarm(): Promise<void> {
try {
console.log(`DatabaseDO: alarm activated`);
} catch (error) {
console.error(`DatabaseDO: alarm execution failed: ${error instanceof Error ? error.message : String(error)}`);
} finally {
// Always schedule next alarm if one isn't set
const currentAlarm = await this.ctx.storage.getAlarm();
if (currentAlarm === null) {
this.ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}
}
// ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}

async fetch(request: Request): Promise<Response> {
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export default {
});
}

// For the Durable Object responses, the CORS headers will be added by the DO handlers
// Each service is represented by its own Durable Object
// - services are grouped by folder in the src directory
// - each service has its own reources and logic
// - we pass the request to the DO and it constructs the response
// - response headers and formatting are handled by shared utils

if (path.startsWith('/auth')) {
const id: DurableObjectId = env.AUTH_DO.idFromName('auth-do'); // create the instance
Expand Down Expand Up @@ -99,6 +103,7 @@ export default {
// Return 404 for any other path
return createUnsupportedEndpointResponse(path, config.SUPPORTED_SERVICES);
} catch (error) {
// Return 500 for any unhandled error
return createApiResponse(`Unknown error: ${error instanceof Error ? error.message : String(error)}`, 500);
}
},
Expand Down
16 changes: 1 addition & 15 deletions src/scheduler/scheduler-do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,7 @@ export class SchedulerDO extends DurableObject<Env> {
this.ALARM_INTERVAL_MS = config.ALARM_INTERVAL_MS;

// Set up alarm to run at configured interval
ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}

async alarm(): Promise<void> {
try {
console.log(`SchedulerDO: alarm activated`);
} catch (error) {
console.error(`SchedulerDO: alarm execution failed: ${error instanceof Error ? error.message : String(error)}`);
} finally {
// Always schedule next alarm if one isn't set
const currentAlarm = await this.ctx.storage.getAlarm();
if (currentAlarm === null) {
this.ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}
}
// ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}

async fetch(request: Request): Promise<Response> {
Expand Down
16 changes: 1 addition & 15 deletions src/tools/tools-do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,7 @@ export class ToolsDO extends DurableObject<Env> {
this.ALARM_INTERVAL_MS = config.ALARM_INTERVAL_MS;

// Set up alarm to run at configured interval
ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}

async alarm(): Promise<void> {
try {
console.log(`ToolsDO: alarm activated`);
} catch (error) {
console.error(`ToolsDO: alarm execution failed: ${error instanceof Error ? error.message : String(error)}`);
} finally {
// Always schedule next alarm if one isn't set
const currentAlarm = await this.ctx.storage.getAlarm();
if (currentAlarm === null) {
this.ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}
}
// ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
}

async fetch(request: Request): Promise<Response> {
Expand Down

0 comments on commit eccc566

Please sign in to comment.