redis#ClientOpts TypeScript Examples

The following examples show how to use redis#ClientOpts. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: app.ts    From jitsi-autoscaler with Apache License 2.0 5 votes vote down vote up
redisQueueOptions = <ClientOpts>{
    host: config.RedisHost,
    port: config.RedisPort,
}
Example #2
Source File: clientRedis.ts    From expresso with MIT License 5 votes vote down vote up
optConfig: ClientOpts = {
  host: REDIS_HOST,
  port: REDIS_PORT,
  password: REDIS_PASSWORD,
}
Example #3
Source File: job_manager.ts    From jitsi-autoscaler with Apache License 2.0 4 votes vote down vote up
createQueue(queueName: string, redisClientOptions: ClientOpts): Queue {
        const newQueue = new Queue(queueName, {
            redis: redisClientOptions,
            removeOnSuccess: true,
            removeOnFailure: true,
        });
        newQueue.on('error', (err) => {
            logger.error(`[QueueProcessor] A queue error happened in queue ${queueName}: ${err.message}`, { err });
            queueErrorCounter.inc();
        });
        newQueue.on('failed', (job, err) => {
            logger.error(
                `[QueueProcessor] Failed processing job ${job.data.type}:${job.id} with error message ${err.message}`,
                { err },
            );
            const jobData: JobData = job.data;
            jobProcessTotalCounter.inc({ type: jobData.type });
            jobProcessFailureCounter.inc({ type: jobData.type });
        });
        newQueue.on('stalled', (jobId) => {
            logger.error(`[QueueProcessor] Stalled job ${jobId}; will be reprocessed`);
            queueStalledCounter.inc();
        });
        newQueue.on('job succeeded', (jobId, result) => {
            logger.info(`Job ${jobId} succeeded with result: ${result}`);
        });
        newQueue.on('job retrying', (jobId, err) => {
            console.log(`Job ${jobId} failed with error ${err.message} but is being retried!`);
        });

        newQueue.process((job: Job, done: DoneCallback<boolean>) => {
            let ctx;
            const start = process.hrtime();

            try {
                const start = Date.now();
                const pollId = shortid.generate();
                const pollLogger = logger.child({
                    id: pollId,
                });
                ctx = new context.Context(pollLogger, start, pollId);

                switch (job.data.type) {
                    case JobType.Autoscale:
                        this.processJob(
                            ctx,
                            job,
                            (ctx, group) => this.autoscaler.processAutoscalingByGroup(ctx, group),
                            done,
                        );
                        break;
                    case JobType.Launch:
                        this.processJob(
                            ctx,
                            job,
                            (ctx, group) => this.instanceLauncher.launchOrShutdownInstancesByGroup(ctx, group),
                            done,
                        );
                        break;
                    case JobType.Sanity:
                        this.processJob(
                            ctx,
                            job,
                            (ctx, group) => this.sanityLoop.reportUntrackedInstances(ctx, group),
                            done,
                        );
                        break;
                    default:
                        this.processJob(ctx, job, () => this.handleUnknownJobType(), done);
                }
            } catch (error) {
                if (ctx) {
                    const delta = process.hrtime(start);
                    ctx.logger.error(
                        `[QueueProcessor] Unexpected error processing job ${job}: ${error}, after ${
                            delta[0] * 1000 + delta[1] / 1000000
                        } ms`,
                    );
                }
                // Ensure done is returned in case of unexpected errors
                return done(error, false);
            }
        });
        return newQueue;
    }