track_progress.mjs 872 B

12345678910111213141516171819202122232425262728293031
  1. // Import the script runner utility (adjust the path as needed)
  2. import { scriptRunner } from '../lib/ScriptRunner.mjs'
  3. const subJobs = 30
  4. /**
  5. * Your script's main work goes here.
  6. * It must be an async function and accept `trackProgress`.
  7. * @param {(message: string) => Promise<void>} trackProgress - Call this to log progress.
  8. */
  9. async function main(trackProgress) {
  10. for (let i = 0; i < subJobs; i++) {
  11. await new Promise(resolve => setTimeout(() => resolve(), 1000))
  12. await trackProgress(`Job in progress ${i + 1}/${subJobs}`)
  13. }
  14. await trackProgress('Job finished')
  15. }
  16. // Define any variables your script needs (optional)
  17. const scriptVariables = {
  18. subJobs,
  19. }
  20. // --- Execute the script using the runner with async/await ---
  21. try {
  22. await scriptRunner(main, scriptVariables)
  23. process.exit()
  24. } catch (error) {
  25. console.error(error)
  26. process.exit(1)
  27. }