This project is no longer in development. A newer version of Conjure is in active development.
w o r k e r
Conjure worker codebase
Queues allow workers to work on tasks as they come in, one at a time.
We use Redis, with Kue for queue workers.
Make sure you have Redis installed, and then run redis-server
in a terminal.
Development works with the default connection setup.
const Queue = require('conjure-core/classes/Queue');
const queue = new Queue('defaultExchange', 'repos', 'github.container.create');
queue.subscribe((err, message) => {
if (err) {
// todo: deal w/ errors, and possibly requeue + ack?
throw err;
}
if (!message.body.content) {
throw new Error('Expected message.body.content');
}
/*
process the queue item
then call message.ack();
*/
});
This codebase also supports directly-called workers. Meaning they do not queues, the calleer must know what server the worker resides on, and will call it directly.
const route = (req, res, next) => {
// ...
};
// must export a route handler
module.exports = route;
// the route will only be available via POST to /github/container/logs/
You must use a process arg to define the subscription notation. Wildcards (*
) are allowed.
E.g.
CONJURE_WORKER_NOTATION="food.dinner.pizza" npm run dev
CONJURE_WORKER_NOTATION="food.dinner.*" npm run dev
CONJURE_WORKER_NOTATION="*" npm run dev
CONJURE_WORKER_NOTATION="*.*.pizza" npm run dev
CONJURE_WORKER_NOTATION="#.pizza" npm run dev
As per RabbitMQ's convention for topic names:
*
can substitute for exactly one word
#
can substitute for zero or more words
To run everything: CONJURE_WORKER_NOTATION="#" npm run dev
We use BeeQueue with Redis to handle our queues. Make sure you have Redis running.
redis-server
If you get this error:
github.container.create --> Error: Build template script exited with code 1
at ChildProcess.buildTemplate.on.code (/Users/mars/tmarshall/conjure-worker/lib/classes/Container/create.js:202:25)
at emitTwo (events.js:125:13)
at ChildProcess.emit (events.js:213:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
github.container.create --> Error: Build template script exited with code 1
at ChildProcess.buildTemplate.on.code (/Users/mars/tmarshall/conjure-worker/lib/classes/Container/create.js:202:25)
at emitTwo (events.js:125:13)
at ChildProcess.emit (events.js:213:7)
Then you have to make sure docker is running locally.
First make sure that the default machine is created. It's often not, on MacOS.
docker-machine start
If that gives you Error: No machine name(s) specified and no "default" machine exists
then run:
docker-machine create default
Now, you can set env vars needed:
eval "$(docker-machine env default)"
Must be an Ubuntu EC2
ssh-keygen
(do not do this on your local...)- save public key as a deploy key on repo, on github
git clone git@github.com:ConjureLabs/conjure-worker.git
sudo apt update
sudo apt-get install postgresql postgresql-contrib redis-tools
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common awscli
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce
sudo -E usermod -a -G docker $USER
- disconnect from ssh, & reconnect
curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -
sudo apt-get install -y nodejs
sudo -E npm i -g pm2
sudo chown -R $USER:$(id -gn $USER) /home/ubuntu/.config
- in proj dir, save
.hob/.env
- in proj dir,
npm install
- run
aws configure
and enter the key, secret, &us-east-1
- in proj dir,
sudo -E pm2 start ./bash/pm2/conjure-worker.sh --name "conjure-worker"
sudo chown ubuntu:ubuntu /home/ubuntu/.pm2/rpc.sock /home/ubuntu/.pm2/pub.sock
(or you can'tpm2 logs
)