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

worker 965B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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, job){
  10. if (err) {
  11. throw err;
  12. }
  13. if (job) {
  14. return render(job);
  15. }
  16. setTimeout(pluckJob, delay());
  17. });
  18. }
  19. function render(job) {
  20. var audiogram = new Audiogram(job.id);
  21. audiogram.settings = job;
  22. audiogram.render(function(err){
  23. if (err) {
  24. audiogram.status("error");
  25. audiogram.set("error", err.toString());
  26. throw err;
  27. }
  28. audiogram.status("ready");
  29. if (process.env.SPAWNED) {
  30. return transports.quit();
  31. }
  32. setTimeout(pluckJob, delay());
  33. });
  34. }
  35. function delay() {
  36. return transports.workerDelay ? transports.workerDelay() : 0;
  37. }