#NEWLINE# def execute( project_id , step_slug ) : #NEWLINE# #INDENT# project = Project . objects . get ( id = project_id ) #NEWLINE# step = Step . objects . get ( slug = function_module , workflow_version = project . workflow_version ) #NEWLINE# task = Task . objects . get ( project = project , step = step ) #NEWLINE# if step . is_human : #NEWLINE# #INDENT# raise MachineExecutionError ( 'Step worker type is not machine' ) #NEWLINE# #UNINDENT# if ( task . status == Task . Status . COMPLETE ) : #NEWLINE# #INDENT# raise MachineExecutionError ( 'Task assignment already completed' ) #NEWLINE# #UNINDENT# with transaction . atomic ( ) : #NEWLINE# #INDENT# ( task_assignment , created ) = TaskAssignment . objects . get_or_create ( assignment_counter = 0 , task = task , defaults = { #NEWLINE# #INDENT# 'status' : TaskAssignment . Status . PROCESSING , #NEWLINE# 'in_progress_task_data' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# if created : #NEWLINE# #INDENT# task . status = Task . Status . PROCESSING #NEWLINE# task . save ( ) #NEWLINE# Iteration . objects . create ( assignment = task_assignment , start_datetime = task_assignment . start_datetime ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( task_assignment . status == TaskAssignment . Status . FAILED ) : #NEWLINE# #INDENT# task_assignment . status = TaskAssignment . Status . PROCESSING #NEWLINE# task_assignment . save ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise MachineExecutionError ( 'Task already picked up by another machine' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# prerequisites = previously_completed_task_data ( task ) #NEWLINE# function_module = import_module ( step . execution_function [ 'module' ] ) #NEWLINE# function = getattr ( function_module , step . execution_function [ 'name' ] ) #NEWLINE# try : #NEWLINE# #INDENT# task_data = function ( project . project_data , prerequisites ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# task_assignment . status = TaskAssignment . Status . FAILED #NEWLINE# logger . exception ( 'Machine task has failed' ) #NEWLINE# task_assignment . save ( ) #NEWLINE# return #NEWLINE# #UNINDENT# task_assignment . status = TaskAssignment . Status . SUBMITTED #NEWLINE# task_assignment . in_progress_task_data = task_data #NEWLINE# task_assignment . save ( ) #NEWLINE# if ( task . project . status == Project . Status . ABORTED ) : #NEWLINE# #INDENT# task . status = Task . Status . ABORTED #NEWLINE# task . save ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# task . status = Task . Status . COMPLETE #NEWLINE# task . save ( ) #NEWLINE# iteration = get_latest_iteration ( task_assignment ) #NEWLINE# iteration . status = Iteration . Status . REQUESTED_REVIEW #NEWLINE# iteration . submitted_data = task_data #NEWLINE# iteration . end_datetime = timezone . now ( ) #NEWLINE# iteration . save ( ) #NEWLINE# create_subsequent_tasks ( project )