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

worker 1.0KB

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