Skip to content

Instantly share code, notes, and snippets.

@kindziora
Last active October 18, 2021 13:38
Show Gist options
  • Save kindziora/b90e0b071117a00fa99fb7ada2958bf9 to your computer and use it in GitHub Desktop.
Save kindziora/b90e0b071117a00fa99fb7ada2958bf9 to your computer and use it in GitHub Desktop.
specs for a mongodb query -> process balancer invoking workers

balancer code

  • load a config
{
  "collection" : "products",
  "match" : { "language" : "de" },
  "queueProperty" : "__mdbqb",
  "cleanUpQueueProperty" : false,
  "allocation" : {
    "command" : "sh command [$__mdbqb.worker]",
    "inParallel" : 10
  }
}

__mdbqb specs

this will be appended to a item inside the collection

 item."queueProperty[__mdbqb]"  = {
  "worker" : "p1",
  "status" : "inprogress|done|open|error",
  "started" : new Date(),
  "finisehd" : new Date()
}

worker code

to be compatible a worker needs to stick to an API spec

  • receive "queueProperty[__mdbqb]" "worker"
  • query for it and update [$__mdbqb.worker]" = p[i] and [$__mdbqb.status]" = "inprogress|done|open|error" and [$__mdbqb.started]" = new Date and [$__mdbqb.started]" = new Date
  • stdout iterator for current item queried by [$__mdbqb.worker]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment