Skip to content

Instantly share code, notes, and snippets.

View jwulf's full-sized avatar
:octocat:
Coding on Halmak

Josh Wulf jwulf

:octocat:
Coding on Halmak
View GitHub Profile
// Production steps of ECMA-262, Edition 5, 15.4.4.19
// Reference: http://es5.github.io/#x15.4.4.19
if (!Array.prototype.map) {
Array.prototype.map = function(callback/*, thisArg*/) {
var T, A, k;
if (this == null) {
throw new TypeError('this is null or not defined');
}
var O = Object(this);
var content = info.data;
var project_arr = [];
var identity = {};
for (var i = 0; i < content.length; i++) {
if (content.length > 0) {
identity.Project_ID = content[i].id;
identity.Project_Name = content[i].name;
identity.Project_Start_Date = content[i].starts_at;
identity.Project_End_Date = content[i].ends_at;
identity.Project_Status = content[i].project_state;
export const JobBuffer = ({
handler,
timeout,
batchSize,
worker,
}: {
handler: ZBBatchWorkerTaskHandler<any, any, any>
timeout: number
batchSize: number
worker: ZBBatchWorker<any, any, any>
import { ZBClient } from 'zeebe-node'
const zbc = new ZBClient()
const batchWorker = zbc.createZBBatchWorker({
taskType: 'rate-limited-api-call',
jobBatchMinSize: 10,
jobBatchMaxTime: 60,
timeout: 80,
taskHandler: (jobs, worker) => {
import { ZBClient } from 'zeebe-node'
const zbc = new ZBClient()
const batchWorker = zbc.createZBBatchWorker({
taskType: 'rate-limited-api-call',
taskHandler: myHandler,
jobBatchMinSize: 10, // first of: every 10 jobs
jobBatchMaxTime: 60, // or every 60 seconds
timeout: 80 // must be greater than jobBatchMaxTime
private createInterceptedGrpcClient(config: GrpcClientCtor) {
const grpcClient = new GrpcClient(config)
grpcClient.on(MiddlewareSignals.Log.Debug, this.debug)
grpcClient.on(MiddlewareSignals.Log.Info, this.info)
grpcClient.on(MiddlewareSignals.Log.Error, this.error)
grpcClient.on(MiddlewareSignals.Event.Error, this.emitError)
grpcClient.on(MiddlewareSignals.Event.Ready, this.emitReady)
return grpcClient
}
private info = (msg: any) => this.log.info(msg)
private handleGrpcError = (stream: any) => async (err: any) => {
// this.emit('error', err)
this.emit(MiddlewareSignals.Event.Error, err)
// this.logger.error(`GRPC ERROR: ${err.message}`)
this.emit(MiddlewareSignals.Log.Error, `GRPC ERROR: ${err.message}`)
const channelState = await this.watchGrpcChannel()
// this.logger.debug(
// `gRPC Channel state: ${connectivityState[channelState]}`
// )
this.emit(
export const MiddlewareSignals = {
Log: {
Error: 'MIDDLEWARE_ERROR',
Info: 'MIDDLEWARE_INFO',
Debug: 'MIDDLEWARE_DEBUG'
},
Event: {
Error: 'error',
Ready: 'ready',
},
export class GrpcMiddleware {
private grpcClient: GrpcClient
private characteristics: Characteristics
private log: ZBLogger
constructor({
profile,
config,
}: {
profile: GrpcConnectionProfile
config: GrpcClientCtor
export class GrpcConnectionFactory {
private static autodetect(config: GrpcClientCtor): GrpcConnectionProfile {
const isCamundaCloud = config.host.includes('zeebe.camunda.io')
return isCamundaCloud ? 'CAMUNDA_CLOUD' : 'VANILLA'
}
public static getGrpcClient(config: GrpcClientCtor) {
const profile = GrpcConnectionFactory.autodetect(config)
return new GrpcMiddleware({ profile, config }).getGrpcClient()
}
}