All files / app/queue producer.js

57.14% Statements 4/7
0% Branches 0/2
0% Functions 0/1
57.14% Lines 4/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21      1x 1x   1x                     1x      
// Part II - Producer.
// Publishes a "zip these tags" job onto the Pub/Sub topic. The @google-cloud/pubsub
// client authenticates automatically via GOOGLE_APPLICATION_CREDENTIALS.
const { PubSub } = require('@google-cloud/pubsub');
const config = require('../config');
 
const pubsub = new PubSub({ projectId: config.projectId });
 
// The exact shape of the message does not matter: the worker parses it back
// the same way on the other side.
function publishZipJob(tags, tagmode) {
  const payload = { tags, tagmode: tagmode || 'all' };
  const dataBuffer = Buffer.from(JSON.stringify(payload));
 
  return pubsub.topic(config.topicName).publishMessage({ data: dataBuffer });
}
 
module.exports = {
  publishZipJob
};