Unverified Commit 58f44ef7 authored by Bennett Piater's avatar Bennett Piater
Browse files

add deploy and enhance tasks pushing to kafka

parent 186e6cb3
#!/bin/bash
set -e
wsk=$1
pushd $(dirname $0)/enhance
zip -ru ../enhance.zip * || true
popd
$wsk -i action update enhance $(dirname $0)/enhance.zip --kind nodejs:8
pushd $(dirname $0)/grayscale
zip -ru ../grayscale.zip * || true
popd
$wsk -i action update consumer $(dirname $0)/grayscale.zip --kind nodejs:8
pushd $(dirname $0)/zip
zip -ru ../zip.zip * || true
popd
$wsk -i action update consumer $(dirname $0)/zip.zip --kind nodejs:8
const gm = require('gm').subClass({imageMagick: true});
const { Kafka, logLevel } = require('kafkajs')
async function writeToKafka(topic, key, json) {
const kafka = new Kafka({
clientId: 'producer',
brokers: ['ark-01.srvs.cloudkafka.com:9094', 'ark-02.srvs.cloudkafka.com:9094', 'ark-03.srvs.cloudkafka.com:9094'],
ssl: true,
sasl: {
mechanism: 'scram-sha-256',
username: 'mra5q18k',
password: 'SddBJrfRgVWkWYCYhaw-J_5pDDDamZsS'
}
});
const producer = kafka.producer()
await producer.connect()
await producer.send({
topic: 'mra5q18k-' + topic,
messages: [{
key: key,
value: json]
})
await producer.disconnect()
return {};
}
function main({filename}) {
// TODO decide how data gets passed in
const image = Buffer.from(data, "base64");
return new Promise((resolve, reject) => {
gm(image, "test.jpg")
// .contrast(-3)
.enhance()
.toBuffer((err, buffer) => {
if (err)
reject({ "error": err });
else {
writeToKafka("topic3", filename + ".enhanced.jpg", '{"data": "' + buffer.toString("base64") + '"}');
resolve({});
}
});
});
}
{
"name": "enhance",
"main": "index.js",
"dependencies": {
"kafkajs": "*"
}
}
const gm = require('gm').subClass({imageMagick: true});
const { Kafka, logLevel } = require('kafkajs')
async function writeToKafka(topic, key, json) {
const kafka = new Kafka({
clientId: 'producer',
brokers: ['ark-01.srvs.cloudkafka.com:9094', 'ark-02.srvs.cloudkafka.com:9094', 'ark-03.srvs.cloudkafka.com:9094'],
ssl: true,
sasl: {
mechanism: 'scram-sha-256',
username: 'mra5q18k',
password: 'SddBJrfRgVWkWYCYhaw-J_5pDDDamZsS'
}
});
const producer = kafka.producer()
await producer.connect()
await producer.send({
topic: 'mra5q18k-' + topic,
messages: [{
key: key,
value: json]
})
await producer.disconnect()
return {};
}
function main({img}) {
// TODO decide how data gets passed in
const image = Buffer.from(img, "base64");
return new Promise((resolve, reject) => {
gm(image, "test.jpg")
.monochrome()
.toBuffer((err, buffer) => {
if (err)
reject({ "error": err });
else {
writeToKafka("topic3", filename + ".grayscaled.jpg", '{"data": "' + buffer.toString("base64") + '"}');
resolve({});
}
});
});
}
{
"name": "grayscale",
"main": "index.js",
"dependencies": {
"kafkajs": "*"
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment