Skip to content

Add option to reset all jobs to 'pending' once all are finished with a new request (looping)#228

Open
BmBaczkowski wants to merge 2 commits intomasterfrom
enhance-ui/add-looping
Open

Add option to reset all jobs to 'pending' once all are finished with a new request (looping)#228
BmBaczkowski wants to merge 2 commits intomasterfrom
enhance-ui/add-looping

Conversation

@BmBaczkowski
Copy link
Copy Markdown
Contributor

Closes #215

  • adds UI to enable looping per study (Study -> Info -> Edit)
  • when all jobs of a participant are finished and a request for a next job comes, then the system checks whether looping is enabled and resets all jobs to pending (lazily triggered by API, no background process), and the jobs are set to 'pending'.
  • edits migration + schema, study model and job results JSON (adds variable to track the count of looping in variable loop_count)
  • adds tests to check the functionality

Additionally, the functionality was tested by manually modifying the DB to mimic client behavior with the procedure described below. @smathot Could you check this independently with a client (instead of curl) whether you get NoJobsForParticipant and tell me your setup?

  1. Initialise fresh DB.
  2. Seed DB node ace migration:refresh and node ace seed.
  3. Start the app npm run dev.
  4. Login to the app, go to Study 1. Ensure looping is off (default setting).
  5. Login to the DB
mysql -h localhost -P 3306 -u ommuser -p omm
  1. Select omm table
USE omm;
  1. Check that looping is indeed off
SELECT loop_enabled FROM studies WHERE id = 1;
  1. View job status of participant 'a'
SELECT j.position, js.status_id
FROM job_states js
JOIN jobs j ON js.job_id = j.id
JOIN participants p ON js.participant_id = p.id
WHERE p.identifier = 'a' AND j.study_id = 1
ORDER BY j.position;

Some jobs should be 'finished' and some 'pending'.
9. Request the index of the first pending job with curl and jq

curl http://localhost:3000/api/v1/participants/a/1/currentjob_idx | jq

It should print position 51.
10. Change the status of all jobs to 'finished'

UPDATE job_states js
JOIN participants p ON js.participant_id = p.id
SET js.status_id = 3
WHERE p.identifier = 'a';
  1. Confirm whether the DB update was successful using command from 8.
  2. Now, request the index of the first pending job with curl and jq using command from 9. It should print 'no jobs available'.
  3. Enable the looping in the UI.
  4. Confirm in the DB using command from 7.
  5. Now, again request the first pending job using command from 9. It should print position 1.
  6. Confirm whether the DB was updated with all jobs set to 'pending' using command from 8.
  7. Set the first job of participant 'a' to 'finished' in the DB:
UPDATE job_states js
JOIN participants p ON js.participant_id = p.id
JOIN jobs j ON js.job_id = j.id
SET js.status_id = 3
WHERE p.identifier = 'a'
  AND j.study_id = 1
  AND j.position = (
    SELECT MIN(position) FROM jobs WHERE study_id = 1
  );

and verify using command from 8.
18. Request the index of the first pending job with curl (command 9) to check if there is any unexpected behavior and verify (command 8).
19. Disable looping in UI.
20. Verify with command 7.
21. Request 'pending' job with curl using command 9. Should print 2.
22. Update DB to set all jobs to 'finished' using command 10.
21. Verify using curl with command 9. Should print 'no jobs'.

When a participant finished the last job and client requests the next job,
the system checks if looping is enabled.
If so, it resets all job states for that participant back to "pending"
Increments the loop_count in the participations table:
loop_count is stored in job_results (change study data model)
Participant starts from the first job again
Only new job_results include loop_count metadata

Relates to #215
@BmBaczkowski BmBaczkowski requested a review from smathot April 26, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optionally reset tasks when no jobs for participant left (looping)

1 participant