Example #1
0
  /**
   * Finishes the task and gets the next one. It returns a promise (which you can call `then` on or use await with).
   * Don't assume that code after the finishAndGetNextTask call will be executed.
   * It can happen that there is no further task, in which case the user will be redirected to the dashboard.
   * Or the the page can be reloaded (e.g., if the dataset changed), which also means that no further JS code will
   * be executed in this site context.
   *
   * @example
   * api.tracing.finishAndGetNextTask().then(() => ... );
   *
   * @example
   * await api.tracing.finishAndGetNextTask();
   */
  async finishAndGetNextTask() {
    const state = Store.getState();
    const { tracingType, annotationId } = state.tracing;
    const task = state.task;

    await Model.save();
    await finishAnnotation(annotationId, tracingType);
    try {
      const annotation = await requestTask();

      const isDifferentDataset = state.dataset.name !== annotation.dataSetName;
      const isDifferentTaskType = annotation.task.type.id !== Utils.__guard__(task, x => x.type.id);

      const currentScript = task != null && task.script != null ? task.script.gist : null;
      const nextScript = annotation.task.script != null ? annotation.task.script.gist : null;
      const isDifferentScript = currentScript !== nextScript;

      const differentTaskTypeParam = isDifferentTaskType ? "?differentTaskType" : "";
      const newTaskUrl = `/annotations/${annotation.typ}/${annotation.id}${differentTaskTypeParam}`;

      // In some cases the page needs to be reloaded, in others the tracing can be hot-swapped
      if (isDifferentDataset || isDifferentTaskType || isDifferentScript) {
        location.href = newTaskUrl;
      } else {
        await this.restart(annotation.typ, annotation.id, ControlModeEnum.TRACE);
      }
    } catch (err) {
      console.error(err);
      await Utils.sleep(2000);
      location.href = "/dashboard";
    }
  }
Example #2
0
  handleNmlDownload = async () => {
    await this.setState({ isDownloading: true });
    // Wait 1 second for the Modal to render
    const [buildInfo] = await Promise.all([getBuildInfo(), Utils.sleep(1000)]);
    const state = Store.getState();
    const nml = serializeToNml(state, this.props.skeletonTracing, buildInfo);
    this.setState({ isDownloading: false });

    const blob = new Blob([nml], { type: "text/plain;charset=utf-8" });
    saveAs(blob, getNmlName(state));
  };
Example #3
0
export async function sendToStore(batch: Array<DataBucket>): Promise<void> {
  const YIELD_AFTER_X_BUCKETS = 3;
  let counter = 0;
  const items = [];
  for (const bucket of batch) {
    counter++;
    // Do not block the main thread for too long as Base64.fromByteArray is performance heavy
    // eslint-disable-next-line no-await-in-loop
    if (counter % YIELD_AFTER_X_BUCKETS === 0) await Utils.sleep(1);
    const bucketData = bucket.getData();
    const bucketInfo = createSendBucketInfo(
      bucket.zoomedAddress,
      getResolutions(Store.getState().dataset),
    );
    items.push(updateBucket(bucketInfo, Base64.fromByteArray(bucketData)));
  }
  Store.dispatch(pushSaveQueueAction(items));
}