@Override
 public void complete(Workspace workspace, Payload payload) throws Exception {
   // Remove active payload
   super.complete(workspace, payload);
   payload.setStatus(Status.COMPLETED);
 }
    public void run() {
      ResourceResolver resourceResolver = null;
      Resource configResource;
      long start = System.currentTimeMillis();
      int total = 0;
      boolean stopped = false;

      try {
        resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
        configResource = resourceResolver.getResource(configPath);

        final Config config = configResource.adaptTo(Config.class);
        final Workspace workspace = config.getWorkspace();

        if (workspace.isStopped()) {
          return;
        }

        try {
          SyntheticWorkflowModel model =
              syntheticWorkflowRunner.getSyntheticWorkflowModel(
                  resourceResolver, config.getWorkflowModelId(), true);
          resourceResolver
              .adaptTo(Session.class)
              .getWorkspace()
              .getObservationManager()
              .setUserData("changedByWorkflowProcess");

          PayloadGroup payloadGroup = null;
          if (workspace.getActivePayloadGroups().size() > 0) {
            payloadGroup = workspace.getActivePayloadGroups().get(0);
          }

          while (payloadGroup != null) {
            List<Payload> payloads = workspace.getActivePayloads();

            if (payloads.size() == 0) {
              // payloads size is 0, so onboard next payload group
              payloadGroup = onboardNextPayloadGroup(workspace, payloadGroup);

              if (payloadGroup != null) {
                payloads = onboardNextPayloads(workspace, payloadGroup);
              }
            }

            // Safety check; if payloads comes in null then immediately break from loop as there is
            // no work to do
            if (payloads == null || payloads.size() == 0) {
              break;
            }

            for (Payload payload : payloads) {
              if (workspace.isStopping() || workspace.isStopped()) {
                stop(workspace);
                stopped = true;
                break;
              }

              try {
                if (config.isAutoThrottle()) {
                  // Wait before starting more work
                  throttledTaskRunner.waitForLowCpuAndLowMemory();
                }

                long processStart = System.currentTimeMillis();
                swr.execute(resourceResolver, payload.getPayloadPath(), model, false, false);
                complete(workspace, payload);
                log.info(
                    "Processed [ {} ] in {} ms",
                    payload.getPayloadPath(),
                    System.currentTimeMillis() - processStart);
              } catch (WorkflowException e) {
                fail(workspace, payload);
                log.warn("Synthetic Workflow could not process [ {} ]", payload.getPath(), e);
              } catch (Exception e) {
                // Complete call failed; consider it failed
                log.warn("Complete call on [ {} ] failed", payload.getPath(), e);
                fail(workspace, payload);
              }

              total++;
            } // end for

            workspace.commit();

            if (stopped) {
              log.info("Bulk Synthetic Workflow run has been stopped.");
              break;
            }
          } // end while

          // Stop check in case a STOP request is made that breaks the while loop
          if (!stopped) {
            complete(workspace);
          }

          log.info(
              "Grand total of [ {} ] payloads saved in {} ms",
              total,
              System.currentTimeMillis() - start);
        } catch (Exception e) {
          log.error("Error processing Bulk Synthetic Workflow execution.", e);
        }
      } catch (LoginException e) {
        log.error("Error processing Bulk Synthetic Workflow execution.", e);
      } finally {
        if (resourceResolver != null) {
          resourceResolver.close();
        }
      }
    }