Skip to content

Commit

Permalink
fix: fallback to new Date()
Browse files Browse the repository at this point in the history
  • Loading branch information
chronark committed Jan 15, 2025
1 parent f6ffe80 commit 1040d1a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default async function AuditPage(props: Props) {

<div className="flex flex-col gap-8 mt-8">
<Filters />

<Suspense
fallback={
<EmptyPlaceholder>
Expand Down
18 changes: 10 additions & 8 deletions apps/workflows/src/workflows/refill_keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ type Params = {};
// <docs-tag name="workflow-entrypoint">
export class RefillRemaining extends WorkflowEntrypoint<Env, Params> {
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
let now = new Date();
try {
// cf stopped sending valid `Date` objects for some reason, so we fall back to Date.now()
now = event.timestamp;
} catch {}

// Set up last day of month so if refillDay is after last day of month, Key will be refilled today.
const lastDayOfMonth = new Date(
event.timestamp.getFullYear(),
event.timestamp.getMonth() + 1,
0,
).getDate();
const today = event.timestamp.getUTCDate();
const lastDayOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0).getDate();
const today = now.getUTCDate();
const db = createConnection({
host: this.env.DATABASE_HOST,
username: this.env.DATABASE_USERNAME,
Expand Down Expand Up @@ -80,7 +82,7 @@ export class RefillRemaining extends WorkflowEntrypoint<Env, Params> {
.update(schema.keys)
.set({
remaining: key.refillAmount,
lastRefillAt: event.timestamp,
lastRefillAt: now,
})
.where(eq(schema.keys.id, key.id));

Expand All @@ -89,7 +91,7 @@ export class RefillRemaining extends WorkflowEntrypoint<Env, Params> {
id: auditLogId,
workspaceId: key.workspaceId,
bucketId: bucketId,
time: event.timestamp.getTime(),
time: now.getTime(),
event: "key.update",
actorId: "trigger",
actorType: "system",
Expand Down

0 comments on commit 1040d1a

Please sign in to comment.