Advertisement
Guest User

launchmon2

a guest
Mar 1st, 2018
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // launch a job on a server against a target,
  2. //  then monitor that job for completion (including the previous sub-job launch, if any)
  3. //  once job is complete, make a new job (by calling make-job-for-target.script)
  4. partial = args[0];  // is this a partial sub-job? (needs to signal completion)
  5. server = args[1];   // run server
  6. target = args[2];   // target
  7. hackThreads = args[3]; //
  8. growThreads = args[4]; // work threads to launch
  9. weakThreads = args[5]; //
  10. monID = args[6];    // supplemental monitor ID (if there is a previous sub-job to monitor, or -1 if not)
  11.  
  12. // append a unique ID in case another copy of this script is already running on this server
  13. function execUniq(script,server,threads,target) {
  14.     uniqID = 0;
  15.     while (isRunning(script,server,target,uniqID)) { ++uniqID; }
  16.     exec(script,server,threads,target,uniqID);
  17.     return uniqID;
  18. }
  19.  
  20. script = null;
  21. uniqID = 0;
  22. if (hackThreads > 0) {
  23.     script = 'hackloop.script';
  24.     uniqID = execUniq(script,server,hackThreads,target);
  25. }
  26. if (growThreads > 0) {
  27.     script = 'grow.script';
  28.     uniqID = execUniq(script,server,growThreads,target);
  29. }
  30. if (weakThreads > 0) {
  31.     script = 'weaken.script';
  32.     uniqID = execUniq(script,server,weakThreads,target);
  33. }
  34. // wait for the slowest job to complete (hack < grow < weak)
  35. while (isRunning(script,server,target,uniqID)) { sleep (1000,false); }
  36.  
  37.  
  38. // if there is a previous sub-job to monitor, wait for it to complete
  39. if (monID >= 0) {
  40.     monFile = target + monID;
  41.     while (read(monFile) === '') { sleep(1000,false); }
  42.     clear(monFile);
  43.     rm(monFile);
  44. }
  45. if (partial) {
  46.     ++monID;
  47.     // if this is a partial sub-job, signal completion to the next sub-job
  48.     write((target + monID),'done');
  49. } else {
  50.     // if this launch completes an entire job, generate a new job
  51.     run('makejob2.script',1,target);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement