source: cows_wps/trunk/process_modules/sync_test1.py @ 7014

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

renamed ddp_process_support to process_support

Line 
1"""
2sync_test1.py
3=============
4
5A very trivial synchronous test using the process_handler interface.
6
7"""
8
9import os, stat, time
10
11from cows_wps.process_handler.fileset import FileSet, FLAG
12import cows_wps.process_handler.process_support as process_support
13from cows_wps.process_handler.context.process_status import STATUS
14
15class SyncTest1(object):
16    def __call__(self, context):
17       
18        startTime = time.time()
19        jobId = os.path.basename(context.processDir)
20        TheInput = context.inputs['TheInput']
21        userId = context.inputs['Username']
22       
23        context.setStatus(STATUS.STARTED, 'Job is now running', 0)
24        context.outputs['answer'] = 'The input is %s' % TheInput
25       
26        filename = 'bar.txt'
27        full_output_dir = context.processDir+'/outputs/'
28        filepath = os.path.join(full_output_dir, filename)
29        fh = open(filepath, 'w')
30        fh.write('The leath police dismiseth us\nThe Input is %s' % TheInput)
31        fh.close()
32        context.log.info('Written bar.txt')
33        filesize = os.stat(filepath)[stat.ST_SIZE]
34   
35        fileSet = context.outputs['FileSet'] = FileSet()
36        fileSet.contents.append(FileSet(FLAG.DATA, filename, filesize, 'The only output'))
37       
38        context.setStatus(STATUS.COMPLETED, 'The End', 100)
39       
40        process_support.writeMetadataFile(context, context.inputs.items())
41       
42        completionTime = time.time()
43        process_support.updateJobDetailsAfterCompletion(context, startTime, completionTime)
44
45
46    def dryRun(self, context):
47        TheInput = context.inputs['TheInput']
48        userId = context.inputs['Username']
49
50        context.log.info('Starting Dry run: TheInput=%s, Username=%s' % (TheInput, userId))
51       
52        jobId = os.path.basename(context.processDir)
53        fileSet = FileSet()
54       
55        fileSet.contents.append(FileSet(FLAG.DATA, 'bar.txt', 40, ''))
56        context.outputs['FileSet'] = fileSet
57
58        process_support.updateJobDetailsAfterDryRun(context, 10)
Note: See TracBrowser for help on using the repository browser.