source: cows_wps/trunk/cows_wps/tests/test_process_code/status_test_process.py @ 7014

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows_wps/trunk/cows_wps/tests/test_process_code/status_test_process.py@7014
Revision 7014, 1.9 KB checked in by astephen, 10 years ago (diff)

renamed ddp_process_support to process_support

Line 
1#!/usr/bin/env python
2"""
3get_data.py
4===========
5
6Holds the GetData class used as a base class for all get data requests and
7is also inherited or at least used by all GetPlot classes to get their
8underlying data.
9
10"""
11import logging
12import time
13
14from cows_wps.process_handler.context.process_status import STATUS
15from cows_wps.process_handler.fileset import FileSet
16from cows_wps.process_handler.process_support import updateJobDetailsAfterCompletion, updateJobDetailsAfterDryRun
17
18log = logging.getLogger(__name__)
19
20class StatusTestProcess(object):
21
22    def __call__(self, context):
23
24        startTime = time.time()
25       
26        if context.inputs['FailAt'] == 'call':
27            self._causeFailure(context)
28        else:
29            context.setStatus(STATUS.COMPLETED, 
30                              context.inputs['CompleteMessage'], 100)
31   
32        completionTime = time.time()
33   
34        updateJobDetailsAfterCompletion(context, startTime, completionTime)
35
36        context.log.info("__call__ end")
37       
38    def dryRun(self, context):
39       
40        estimatedDuration = context.inputs['EstimatedDuration']
41        context.outputs['job_details']['estimated_duration'] = estimatedDuration
42
43        context.outputs['FileSet'] = FileSet()       
44
45        if context.inputs['FailAt'] == 'dryrun':
46            self._causeFailure(context)
47        else:
48            context.setStatus(STATUS.ACCEPTED, 
49                context.inputs['AcceptMessage'], 0)
50           
51        updateJobDetailsAfterDryRun(context, estimatedDuration)
52
53        context.log.info("dryRun end")
54             
55    def _causeFailure(self, context):
56        message = context.inputs['FailMessage']
57       
58        if context.inputs['FailType'] == 'exception':
59            raise Exception(message)
60        elif context.inputs['FailType'] == 'status':
61            context.setStatus(STATUS.FAILED, message)
62           
Note: See TracBrowser for help on using the repository browser.