mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-04 15:34:13 +00:00 
			
		
		
		
	log inbound activity duration
This commit is contained in:
		
							parent
							
								
									07cd01ec34
								
							
						
					
					
						commit
						e35e92beb9
					
				
					 3 changed files with 35 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -0,0 +1,19 @@
 | 
			
		|||
/*
 | 
			
		||||
 * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
 | 
			
		||||
 * SPDX-License-Identifier: AGPL-3.0-only
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
export class ActivityLogTiming1731909785724 {
 | 
			
		||||
    name = 'ActivityLogTiming1731909785724'
 | 
			
		||||
 | 
			
		||||
    async up(queryRunner) {
 | 
			
		||||
        await queryRunner.query(`ALTER TABLE "activity_log" ADD "duration" double precision NOT NULL DEFAULT '0'`);
 | 
			
		||||
        await queryRunner.query(`ALTER TABLE "activity_log" ALTER COLUMN "result" DROP NOT NULL`);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async down(queryRunner) {
 | 
			
		||||
				await queryRunner.query(`UPDATE "activity_log" SET "result" = 'not processed' WHERE "result" IS NULL`);
 | 
			
		||||
        await queryRunner.query(`ALTER TABLE "activity_log" ALTER COLUMN "result" SET NOT NULL`);
 | 
			
		||||
        await queryRunner.query(`ALTER TABLE "activity_log" DROP COLUMN "duration"`);
 | 
			
		||||
		}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -20,6 +20,12 @@ export class SkActivityLog {
 | 
			
		|||
	@Column('timestamptz')
 | 
			
		||||
	public at: Date;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Processing duration in milliseconds
 | 
			
		||||
	 */
 | 
			
		||||
	@Column('double precision', { default: 0 })
 | 
			
		||||
	public duration = 0;
 | 
			
		||||
 | 
			
		||||
	@Column({
 | 
			
		||||
		type: 'text',
 | 
			
		||||
		name: 'key_id',
 | 
			
		||||
| 
						 | 
				
			
			@ -36,8 +42,8 @@ export class SkActivityLog {
 | 
			
		|||
	@Column('boolean')
 | 
			
		||||
	public accepted: boolean;
 | 
			
		||||
 | 
			
		||||
	@Column('text')
 | 
			
		||||
	public result: string;
 | 
			
		||||
	@Column('text', { nullable: true })
 | 
			
		||||
	public result: string | null = null;
 | 
			
		||||
 | 
			
		||||
	@Column('jsonb')
 | 
			
		||||
	// https://github.com/typeorm/typeorm/issues/8559
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -98,9 +98,16 @@ export class InboxProcessorService implements OnApplicationShutdown {
 | 
			
		|||
		}
 | 
			
		||||
 | 
			
		||||
		try {
 | 
			
		||||
			const startTime = process.hrtime.bigint();
 | 
			
		||||
			const result = await this._process(job, log);
 | 
			
		||||
			const endTime = process.hrtime.bigint();
 | 
			
		||||
 | 
			
		||||
			// Truncate nanoseconds to microseconds, then scale to milliseconds.
 | 
			
		||||
			// 123,456,789 ns -> 123,456 us -> 123.456 ms
 | 
			
		||||
			const duration = Number((endTime - startTime) / 1000n) / 1000;
 | 
			
		||||
 | 
			
		||||
			log.accepted = result.startsWith('ok');
 | 
			
		||||
			log.duration = duration;
 | 
			
		||||
			log.result = result;
 | 
			
		||||
 | 
			
		||||
			return result;
 | 
			
		||||
| 
						 | 
				
			
			@ -249,7 +256,7 @@ export class InboxProcessorService implements OnApplicationShutdown {
 | 
			
		|||
			delete activity.id;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Attach log to verified user
 | 
			
		||||
		// Record verified user in log
 | 
			
		||||
		if (log) {
 | 
			
		||||
			log.verified = true;
 | 
			
		||||
			log.authUser = authUser.user;
 | 
			
		||||
| 
						 | 
				
			
			@ -361,7 +368,6 @@ export class InboxProcessorService implements OnApplicationShutdown {
 | 
			
		|||
			at: new Date(),
 | 
			
		||||
			verified: false,
 | 
			
		||||
			accepted: false,
 | 
			
		||||
			result: 'not processed',
 | 
			
		||||
			activity,
 | 
			
		||||
			keyId,
 | 
			
		||||
			host,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue