kopia lustrzana https://github.com/cloudflare/wildebeest
debug
rodzic
c308293d7d
commit
d4c1e980f3
|
@ -2,7 +2,7 @@ name: Deploy
|
|||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- sven/debug5
|
||||
repository_dispatch:
|
||||
jobs:
|
||||
deploy:
|
||||
|
|
|
@ -128,7 +128,16 @@ export async function cacheObject(
|
|||
}
|
||||
|
||||
{
|
||||
const properties = JSON.parse(row.properties)
|
||||
let properties
|
||||
if (typeof row.properties === 'object') {
|
||||
// neon uses JSONB for properties which is returned as a deserialized
|
||||
// object.
|
||||
properties = row.properties
|
||||
} else {
|
||||
// D1 uses a string for JSON properties
|
||||
properties = JSON.parse(row.properties)
|
||||
}
|
||||
|
||||
const object = {
|
||||
published: new Date(row.cdate).toISOString(),
|
||||
...properties,
|
||||
|
@ -206,7 +215,16 @@ export async function getObjectBy(db: Database, key: ObjectByKey, value: string)
|
|||
}
|
||||
|
||||
const result: any = results[0]
|
||||
const properties = JSON.parse(result.properties)
|
||||
|
||||
let properties
|
||||
if (typeof row.properties === 'object') {
|
||||
// neon uses JSONB for properties which is returned as a deserialized
|
||||
// object.
|
||||
properties = row.properties
|
||||
} else {
|
||||
// D1 uses a string for JSON properties
|
||||
properties = JSON.parse(row.properties)
|
||||
}
|
||||
|
||||
return {
|
||||
published: new Date(result.cdate).toISOString(),
|
||||
|
|
|
@ -35,6 +35,7 @@ export default function make({ DATABASE }: Pick<Env, 'DATABASE'>): Database {
|
|||
const db = DATABASE as any
|
||||
db.qb = qb
|
||||
db.client = 'd1'
|
||||
db.closeConnection = async () => {}
|
||||
|
||||
return db as Database
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ export interface Database {
|
|||
exec<T = unknown>(query: string): Promise<Result<T>>
|
||||
qb: QueryBuilder
|
||||
client: string
|
||||
closeConnection(): Promise<void>
|
||||
}
|
||||
|
||||
export interface PreparedStatement {
|
||||
|
|
|
@ -48,6 +48,12 @@ export default async function make(env: Pick<Env, 'NEON_DATABASE_URL'>): Promise
|
|||
client: 'neon',
|
||||
qb,
|
||||
|
||||
async closeConnection() {
|
||||
console.log("closeConnection");
|
||||
await client.end()
|
||||
console.log("did closeConnection");
|
||||
},
|
||||
|
||||
prepare(query: string) {
|
||||
return new PreparedStatement(env, query, [], client)
|
||||
},
|
||||
|
@ -102,6 +108,7 @@ export class PreparedStatement {
|
|||
throw new Error('not implemented')
|
||||
}
|
||||
const query = sqliteToPsql(this.query)
|
||||
console.log({ query })
|
||||
|
||||
const results = await this.client.query(query, this.values)
|
||||
if (results.rows.length !== 1) {
|
||||
|
@ -117,6 +124,7 @@ export class PreparedStatement {
|
|||
|
||||
async all<T = unknown>(): Promise<Result<T>> {
|
||||
const query = sqliteToPsql(this.query)
|
||||
console.log({ query })
|
||||
const results = await this.client.query(query, this.values)
|
||||
|
||||
return {
|
||||
|
|
|
@ -13,7 +13,6 @@ export async function handleInboxMessage(env: Env, actor: Actor, message: InboxM
|
|||
const adminEmail = env.ADMIN_EMAIL
|
||||
const cache = cacheFromEnv(env)
|
||||
const activity = message.activity
|
||||
console.log(JSON.stringify(activity))
|
||||
|
||||
await activityHandler.handle(domain, activity, db, message.userKEK, adminEmail, message.vapidKeys)
|
||||
|
||||
|
|
|
@ -22,10 +22,12 @@ export type Env = {
|
|||
export default {
|
||||
async queue(batch: MessageBatch<MessageBody>, env: Env, ctx: ExecutionContext) {
|
||||
const sentry = initSentryQueue(env, ctx)
|
||||
const db = await getDatabase(env)
|
||||
|
||||
try {
|
||||
for (const message of batch.messages) {
|
||||
for (const message of batch.messages) {
|
||||
console.log(JSON.stringify(message))
|
||||
const db = await getDatabase(env)
|
||||
|
||||
try {
|
||||
const actor = await actors.getActorById(db, new URL(message.body.actorId))
|
||||
if (actor === null) {
|
||||
console.warn(`actor ${message.body.actorId} is missing`)
|
||||
|
@ -42,14 +44,17 @@ export default {
|
|||
break
|
||||
}
|
||||
default:
|
||||
throw new Error('unsupported message type: ' + message.body.type)
|
||||
console.warn('unsupported message type: ' + message.body.type)
|
||||
}
|
||||
} catch (err: any) {
|
||||
if (sentry !== null) {
|
||||
sentry.captureException(err)
|
||||
}
|
||||
console.error(err.stack, err.cause)
|
||||
throw err
|
||||
} finally {
|
||||
await db.closeConnection()
|
||||
}
|
||||
} catch (err: any) {
|
||||
if (sentry !== null) {
|
||||
sentry.captureException(err)
|
||||
}
|
||||
console.error(err.stack, err.cause)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ resource "random_password" "user_key" {
|
|||
resource "cloudflare_pages_project" "wildebeest_pages_project" {
|
||||
account_id = var.cloudflare_account_id
|
||||
name = "wildebeest-${lower(var.name_suffix)}"
|
||||
production_branch = "main"
|
||||
production_branch = "sven/debug5"
|
||||
|
||||
deployment_configs {
|
||||
production {
|
||||
|
|
Ładowanie…
Reference in New Issue