Skip to content

Instantly share code, notes, and snippets.

View pravinchandar's full-sized avatar
🎯
Focusing

Pravin Raajendiran pravinchandar

🎯
Focusing
  • Sydney
  • 19:49 (UTC -12:00)
View GitHub Profile
// badTransformations keeps track of expr that resulted in the jqworker process
// getting killed.
//
// Need to set a TTL (or some eviction policy) on the map so its growth is deterministic.
var badTransformations = make(map[string]int)
// JqTransform runs transformation on the jqserver
func JqTransform(rpcClient *rpc.Client, input SomeInput) (*SomeOutput, error) {
if badTransformations[params.Expression] == 3 {
return nil, errors.New("skipping potential resource exhaustive transformation")
func JqTransform(rpcClient *rpc.Client, input SomeInput) (*SomeOutput, error) {
output := &SomeOutput{}
err := rpcClient.Call("Jqserver.Evaluate", input, output)
return output, err
}
rpcClient, err := rpc.Dial("unix", "/tmp/jqserver.sock")
if err != nil {
panic(fmt.Sprintf("failed to initialise rpc client: %v", err))
}
// Evaluate is an RPC proxy. It proxies the request to the main process and
// writes the response to o.
func (j JqServer) Evaluate(i *SomeInput, o *SomeOutput) error {
// setup the conduit
reqChan := make(chan RequestResponse)
req := RequestResponse{Req: i}
// send the request to the main process
j.process.ReqRespChan <- reqChan
reqChan <- req
// RequestResponse represents the rpc request
type RequestResponse struct {
Req SomeRequestType
Res SomeResponseType
Error error
}
// Process is the jqserver process
type Process struct {
// ReqRespChan is the interface to the jqserver loop
// Run runs main server loop, it launches the desired count of worker processes
// and also manage them. It listens for requests on the ReqChan. The request is
// then sent to one of the worker processes for processing. The response from
// the worker is then written to the channel supplied by the client via
// ReqChan. It listens for termination signal on the sigChan.
func (p *Process) Run(ctx context.Context, sigChan chan struct{}) {
// Start by signaling to create num workers
createWorker := make(chan struct{})
go func() { createWorker <- struct{}{} }()
{
"current_pod": "998",
"home_pod": "998"
}

Keybase proof

I hereby claim:

  • I am pravinchandar on github.
  • I am pravin (https://keybase.io/pravin) on keybase.
  • I have a public key whose fingerprint is E85B 44D8 1335 1458 D47B 085C 5572 72E4 5AE8 724A

To claim this, I am signing this object: