<s> from __future__ import absolute_import , division , unicode_literals <EOL> from changes . api . base import APIView <EOL> from changes . constants import Result , Status <EOL> from changes . config import db <EOL> from changes . jobs . sync_job_step import sync_job_step <EOL> from changes . models import JobStep <EOL> class JobStepDeallocateAPIView ( APIView ) : <EOL> def post ( self , step_id ) : <EOL> to_deallocate = JobStep . query . get ( step_id ) <EOL> if to_deallocate is None : <EOL> return '<STR_LIT>' , <NUM_LIT> <EOL> if to_deallocate . status not in ( Status . allocated , Status . in_progress ) : <EOL> return { <EOL> "<STR_LIT:error>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : to_deallocate . status . name <EOL> } , <NUM_LIT> <EOL> to_deallocate . status = Status . pending_allocation <EOL> to_deallocate . result = Result . unknown <EOL> to_deallocate . date_started = None <EOL> to_deallocate . date_finished = None <EOL> db . session . add ( to_deallocate ) <EOL> db . session . commit ( ) <EOL> sync_job_step . delay ( <EOL> step_id = to_deallocate . id . hex , <EOL> task_id = to_deallocate . id . hex , <EOL> parent_task_id = to_deallocate . job_id . hex , <EOL> ) <EOL> return self . respond ( to_deallocate ) </s>
