def _handle_new_page(self, workflow_run, page): """ For the pages that has been added later but were not there during the original run, we simply run the all the jobs in the workflow. The problem is, if someone edited the workflow in the meantime, the new workflow jobs will be run against the new pages, not the old workflow jobs. """ # This method should be refactored. I literally copied code from up there. # Maybe *after* I write some unit tests? workflow_jobs = workflow_run.workflow.workflow_jobs.all() workflow_chain = [] for workflow_job in workflow_jobs: is_interactive = False if workflow_job.job_type == 0 else True runjob = RunJob(workflow_run=workflow_run, workflow_job=workflow_job, job_settings=workflow_job.job_settings, needs_input=is_interactive, page=page) runjob.save() rodan_task = registry.tasks[str(workflow_job.job_name)] workflow_chain.append((rodan_task, str(runjob.uuid))) first_job = workflow_chain[0] res = chain([first_job[0].si(None, first_job[1])] + [job[0].s(job[1]) for job in workflow_chain[1:]]) res.apply_async()
def _handle_new_page(self, workflow_run, page): """ For the pages that has been added later but were not there during the original run, we simply run the all the jobs in the workflow. The problem is, if someone edited the workflow in the meantime, the new workflow jobs will be run against the new pages, not the old workflow jobs. """ # This method should be refactored. I literally copied code from up there. # Maybe *after* I write some unit tests? workflow_jobs = workflow_run.workflow.workflow_jobs.all() workflow_chain = [] for workflow_job in workflow_jobs: is_interactive = False if workflow_job.job_type == 0 else True runjob = RunJob( workflow_run=workflow_run, workflow_job=workflow_job, job_settings=workflow_job.job_settings, needs_input=is_interactive, page=page, ) runjob.save() rodan_task = registry.tasks[str(workflow_job.job_name)] workflow_chain.append((rodan_task, str(runjob.uuid))) first_job = workflow_chain[0] res = chain([first_job[0].si(None, first_job[1])] + [job[0].s(job[1]) for job in workflow_chain[1:]]) res.apply_async()
def test_save(self): test_runjob = RunJob(workflow_run=self.test_workflowrun, workflow_job=self.test_workflowjob) test_runjob.save() # test that the paths were created properly #rj_path = test_runjob.runjob_path #self.assertTrue(os.path.exists(rj_path)) retr_runjob = RunJob.objects.get(uuid=test_runjob.pk) self.assertEqual(retr_runjob, test_runjob) retr_runjob.delete()
def test_save(self): test_runjob = RunJob(workflow_run=self.test_workflowrun, workflow_job=self.test_workflowjob, page=self.test_page) test_runjob.save() # test that the paths were created properly rj_path = test_runjob.runjob_path self.assertTrue(os.path.exists(rj_path)) retr_runjob = RunJob.objects.get(uuid=test_runjob.pk) self.assertEqual(retr_runjob, test_runjob) retr_runjob.delete()
def post(self, request, *args, **kwargs): """ In the Rodan RESTful architecture, "running" a workflow is accomplished by creating a new WorkflowRun object. """ # workflow = request.QUERY_PARAMS.get('workflow', None) workflow = request.DATA.get('workflow', None) test_status = request.QUERY_PARAMS.get('test', None) page_id = request.QUERY_PARAMS.get('page_id', None) if not workflow: return Response({"message": "You must specify a workflow ID"}, status=status.HTTP_400_BAD_REQUEST) value = urlparse.urlparse(workflow).path try: w = resolve(value) except: return Response( {"message": "Could not resolve ID to workflow object"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) try: workflow_obj = Workflow.objects.get(pk=w.kwargs.get('pk')) except: return Response( {"message": "You must specify an existing workflow"}, status=status.HTTP_404_NOT_FOUND) workflow_jobs = WorkflowJob.objects.filter( workflow=workflow_obj).order_by('sequence') if not workflow_jobs.exists(): return Response( { "message": "No jobs for workflow {0} were specified".format(workflow) }, status=status.HTTP_400_BAD_REQUEST) if test_status: # running in test mode. This runs the workflow on a single page. if not page_id: return Response( { "message": "You must specify a page ID if you are running in test mode." }, status=status.HTTP_400_BAD_REQUEST) value = urlparse.urlparse(page_id).path try: p = resolve(value) except: return Response({}, status=status.HTTP_400_BAD_REQUEST) pages = Page.objects.filter(pk=p.kwargs.get('pk')) run_num = None test_status = True if not pages.exists(): return Response( { "message": "No pages for page ID {0} were found".format(page_id) }, status=status.HTTP_400_BAD_REQUEST) else: pages = workflow_obj.pages.filter(processed=True) run_num = workflow_obj.runs + 1 test_status = False if not pages: return Response( { "message": "No pages were assigned to workflow ID {0}".format( workflow) }, status=status.HTTP_400_BAD_REQUEST) workflow_run = WorkflowRun(workflow=workflow_obj, run=run_num, test_run=test_status, creator=request.user) workflow_run.save() return_objects = [] for page in pages: workflow_chain = [] for workflow_job in workflow_jobs: is_interactive = False if workflow_job.job_type == 0 else True runjob = RunJob( workflow_run=workflow_run, workflow_job=workflow_job, job_settings=workflow_job. job_settings, # copy the most recent settings from the workflow job (these may be modified if the job is interactive) needs_input= is_interactive, # by default this is set to be True if the job is interactive page=page, sequence=workflow_job.sequence) runjob.save() rodan_task = registry.tasks[str(workflow_job.job_name)] workflow_chain.append((rodan_task, str(runjob.uuid))) first_job = workflow_chain[0] res = chain([first_job[0].si(None, first_job[1])] + [job[0].s(job[1]) for job in workflow_chain[1:]]) res.apply_async() return_objects.append(res) if not test_status: # If we're not doing a test run, update the run count on the workflow workflow_obj.runs = run_num return Response({"message": workflow_run.get_absolute_url()}, status=status.HTTP_201_CREATED)
def post(self, request, *args, **kwargs): """ In the Rodan RESTful architecture, "running" a workflow is accomplished by creating a new WorkflowRun object. """ # workflow = request.QUERY_PARAMS.get('workflow', None) workflow = request.DATA.get("workflow", None) test_status = request.QUERY_PARAMS.get("test", None) page_id = request.QUERY_PARAMS.get("page_id", None) if not workflow: return Response({"message": "You must specify a workflow ID"}, status=status.HTTP_400_BAD_REQUEST) value = urlparse.urlparse(workflow).path try: w = resolve(value) except: return Response( {"message": "Could not resolve ID to workflow object"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR ) try: workflow_obj = Workflow.objects.get(pk=w.kwargs.get("pk")) except: return Response({"message": "You must specify an existing workflow"}, status=status.HTTP_404_NOT_FOUND) workflow_jobs = WorkflowJob.objects.filter(workflow=workflow_obj).order_by("sequence") if not workflow_jobs.exists(): return Response( {"message": "No jobs for workflow {0} were specified".format(workflow)}, status=status.HTTP_400_BAD_REQUEST, ) if test_status: # running in test mode. This runs the workflow on a single page. if not page_id: return Response( {"message": "You must specify a page ID if you are running in test mode."}, status=status.HTTP_400_BAD_REQUEST, ) value = urlparse.urlparse(page_id).path try: p = resolve(value) except: return Response({}, status=status.HTTP_400_BAD_REQUEST) pages = Page.objects.filter(pk=p.kwargs.get("pk")) run_num = None test_status = True if not pages.exists(): return Response( {"message": "No pages for page ID {0} were found".format(page_id)}, status=status.HTTP_400_BAD_REQUEST, ) else: pages = workflow_obj.pages.filter(processed=True) run_num = workflow_obj.runs + 1 test_status = False if not pages: return Response( {"message": "No pages were assigned to workflow ID {0}".format(workflow)}, status=status.HTTP_400_BAD_REQUEST, ) workflow_run = WorkflowRun(workflow=workflow_obj, run=run_num, test_run=test_status, creator=request.user) workflow_run.save() return_objects = [] for page in pages: workflow_chain = [] for workflow_job in workflow_jobs: is_interactive = False if workflow_job.job_type == 0 else True runjob = RunJob( workflow_run=workflow_run, workflow_job=workflow_job, job_settings=workflow_job.job_settings, # copy the most recent settings from the workflow job (these may be modified if the job is interactive) needs_input=is_interactive, # by default this is set to be True if the job is interactive page=page, sequence=workflow_job.sequence, ) runjob.save() rodan_task = registry.tasks[str(workflow_job.job_name)] workflow_chain.append((rodan_task, str(runjob.uuid))) first_job = workflow_chain[0] res = chain([first_job[0].si(None, first_job[1])] + [job[0].s(job[1]) for job in workflow_chain[1:]]) res.apply_async() return_objects.append(res) if not test_status: # If we're not doing a test run, update the run count on the workflow workflow_obj.runs = run_num return Response({"message": workflow_run.get_absolute_url()}, status=status.HTTP_201_CREATED)