11import Bluebird = require( 'bluebird' )
22import redislock = require( '@microfleet/ioredis-lock' )
33import Redis = require( 'ioredis' )
4- import pino = require ( 'pino' )
4+ import { pino } from 'pino'
55import assert = require( 'assert' )
66import readPkg = require( 'read-pkg-up' )
77
@@ -15,15 +15,14 @@ import compose = require('lodash/fp/compose')
1515import * as callbackQueue from './callback-queue'
1616import { Semaphore } from './semaphore'
1717import { MultiLock , MultiLockError } from './multi-lock'
18- import P = require( 'pino' )
1918import { Thunk } from '@microfleet/callback-queue'
2019
2120const { LockAcquisitionError } = redislock
2221const isBoolean = filter < string > ( Boolean )
2322const toFlattenedTruthyArray = compose ( isBoolean , flatten )
2423const couldNotAcquireLockError = new LockAcquisitionError ( 'job is already running' )
2524const TimeoutError = new Bluebird . TimeoutError ( 'queue-no-response' )
26- const notLockAcquisitionError = ( e : Error ) => e . name !== 'LockAcquisitionError'
25+ const notLockAcquisitionError = ( e : unknown ) : e is Error => e instanceof Error && e . name !== 'LockAcquisitionError'
2726const isTimeoutError = ( e : unknown ) : e is typeof TimeoutError => e === TimeoutError
2827const pkg = readPkg . sync ( ) ?. packageJson
2928
@@ -32,7 +31,7 @@ export interface Config {
3231 pubsub : Redis . Redis | Redis . Cluster
3332 pubsubChannel : string
3433 lock : Partial < redislock . Config >
35- log : P . Logger | boolean
34+ log : pino . Logger | boolean
3635 lockPrefix : string
3736 debug : boolean
3837 name : string
@@ -66,7 +65,7 @@ function hasProp<K extends PropertyKey>(data: object, prop: K): data is Record<K
6665 * @param lockPrefix - used for creating locks in redis
6766 */
6867export class DistributedCallbackQueue {
69- public readonly logger : P . Logger
68+ public readonly logger : pino . Logger
7069 private readonly lockPrefix : string
7170 private readonly client : Config [ 'client' ]
7271 private readonly pubsub : Config [ 'pubsub' ]
@@ -108,7 +107,7 @@ export class DistributedCallbackQueue {
108107 this . logger . info ( 'Initialized...' )
109108 }
110109
111- static isCompatibleLogger ( logger : unknown ) : logger is P . Logger {
110+ static isCompatibleLogger ( logger : unknown ) : logger is pino . Logger {
112111 if ( typeof logger !== 'object' || logger == null ) {
113112 return false
114113 }
@@ -122,7 +121,7 @@ export class DistributedCallbackQueue {
122121 return true
123122 }
124123
125- static initLogger ( options : Partial < Pick < Config , 'log' | 'debug' | 'name' > > ) : P . Logger {
124+ static initLogger ( options : Partial < Pick < Config , 'log' | 'debug' | 'name' > > ) : pino . Logger {
126125 const { log : logger , debug, name } = options
127126 const loggerEnabled = typeof logger === 'undefined' ? ! ! debug : logger
128127
@@ -198,7 +197,7 @@ export class DistributedCallbackQueue {
198197 try {
199198 await lock . acquire ( lockRedisKey )
200199 return this . createWorker ( lockRedisKey , lock )
201- } catch ( e ) {
200+ } catch ( e : unknown ) {
202201 if ( notLockAcquisitionError ( e ) ) {
203202 // this is an abnormal error, need to post it and cancel requests
204203 // so that they dont hang
0 commit comments