hello_world.job.agi 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. Hello World - the job half
  3. The cluster runs this file once on every node it is sent to (see
  4. hello_world.agi). The runtime calls run(job) and publishes whatever it
  5. returns as the job output, so the reply is just a plain object.
  6. job = {id, name, args, inputs, node, owner} plus the helpers
  7. job.log(text), job.progress(0..1), job.cancelled() and
  8. job.abortIfCancelled().
  9. */
  10. requirelib("cluster");
  11. function run(job) {
  12. //cluster.self() is the view of the node this job is running on
  13. var me = cluster.self();
  14. var caps = me.capabilities || {};
  15. var health = me.health || {};
  16. //Only list the features this node actually has
  17. var features = [];
  18. for (var name in (caps.features || {})) {
  19. if (caps.features[name]) {
  20. features.push(name);
  21. }
  22. }
  23. features.sort();
  24. job.log("Hello World from " + me.name);
  25. return {
  26. message: "Hello World from " + me.name,
  27. node: {
  28. id: me.id,
  29. name: me.name,
  30. state: me.state,
  31. version: me.version,
  32. os: caps.os,
  33. arch: caps.arch,
  34. hostname: caps.hostname,
  35. cpuCores: caps.cpuCores,
  36. totalRamBytes: caps.totalRam,
  37. features: features
  38. },
  39. health: {
  40. cpuUsagePercent: health.cpuUsage,
  41. ramUsedBytes: health.ramUsed,
  42. diskFreeBytes: health.diskFree,
  43. uptimeSeconds: health.uptime
  44. },
  45. runAs: job.owner,
  46. jobId: job.id,
  47. answeredAt: new Date().toISOString()
  48. };
  49. }