code: public void deleteJobPlanAssociatedEntities(JobInstance job) {
          JobPlan jobPlan = loadPlan(job.getId());
          environmentVariableDao.deleteAll(jobPlan.getVariables());
          artifactPlanRepository.deleteAll(jobPlan.getArtifactPlansOfType(ArtifactPlanType.file));
          artifactPropertiesGeneratorRepository.deleteAll(jobPlan.getPropertyGenerators());
          resourceRepository.deleteAll(jobPlan.getResources());
          if (jobPlan.requiresElasticAgent()) {
              jobAgentMetadataDao.delete(jobAgentMetadataDao.load(jobPlan.getJobId()));
          }
      }
docs: this will be called from Job Status Listener when Job is completed.