empiricaly / empirica

Open source project to tackle the problem of long development cycles required to produce software to conduct multi-participant and real-time human experiments online.
https://empirica.ly/
Apache License 2.0
47 stars 8 forks source link

Await "on batch" callback before allowing admin to run the batch #416

Open JamesPHoughton opened 1 year ago

JamesPHoughton commented 1 year ago

Is there an existing issue for this?

Is your feature request related to a problem?

Currently I'm using a callback when a batch is created to do a bunch of initialization stuff, in an async way:

Empirica.on("batch", async (ctx, { batch }) => {
  // fetch data
  // check that I have all the required resources
  // check configs
  // validate the treatment
  // etc.
}

the problem (and its a small one) is that I can start the batch (and run all the batch start callbacks) before this has finished. Then, if the batch start callback is expecting the batch creation callback to have finished its initialization stuff, it either can check for initialization and intentionally go to a "failed" state batch.set("status", "failed") or (more likely, as I assumed the initialization had finished) behave unpredictably.

Describe the solution you'd like

Possibly create an additional state a batch can be in that is created by not ready to start yet. (Initializing?) that gets set when the batch creation callback resolves.

Describe alternatives you've considered

Currently I manually check that initialization has finished in the batch start callback, and if it has not, fail the batch.

Teachability, Documentation, Adoption, Migration Strategy

Should be transparent to most users.

Code of Conduct