Turn audio into a shareable video. forked from nypublicradio/audiogram

worker 1021B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env node
  2. var dotenv = require("dotenv").config({silent: true}),
  3. Audiogram = require("../audiogram/"),
  4. transports = require("../lib/transports/");
  5. // Can only register fonts once, double-registering throws an error
  6. require("../lib/register-fonts.js");
  7. pluckJob();
  8. function pluckJob(){
  9. transports.getJob(function(err, settings){
  10. if (err) {
  11. throw err;
  12. }
  13. if (settings) {
  14. return render(settings);
  15. }
  16. setTimeout(pluckJob, delay());
  17. });
  18. }
  19. function render(settings) {
  20. var audiogram = new Audiogram(settings.id);
  21. // TODO rename to theme
  22. audiogram.settings = settings;
  23. audiogram.render(function(err){
  24. if (err) {
  25. audiogram.status("error");
  26. audiogram.set("error", err.toString());
  27. throw err;
  28. }
  29. audiogram.status("ready");
  30. if (process.env.SPAWNED) {
  31. return transports.quit();
  32. }
  33. setTimeout(pluckJob, delay());
  34. });
  35. }
  36. function delay() {
  37. return transports.workerDelay ? transports.workerDelay() : 0;
  38. }