blob: f21963346981511aae96e8b251149557a6cca69c [file] [log] [blame]
Taka Cho18510892019-05-14 17:37:24 -04001/*
2============LICENSE_START==========================================
3===================================================================
4Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
5===================================================================
6
7Unless otherwise specified, all software contained herein is licensed
8under the Apache License, Version 2.0 (the License);
9you may not use this software except in compliance with the License.
10You may obtain a copy of the License at
11
12 http://www.apache.org/licenses/LICENSE-2.0
13
14Unless required by applicable law or agreed to in writing, software
15distributed under the License is distributed on an "AS IS" BASIS,
16WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17See the License for the specific language governing permissions and
18limitations under the License.
19
20============LICENSE_END============================================ */
21//... deleteOldData.js - to be started by parent server process
22const fs = require('fs');
23
24var logger = require('./srvlogger');
25
26var clName= "deleteOldData";
27var cdt_home = ".";
28
29 this.thePid= process.pid;
30 console.log(clName+": thePid="+this.thePid );
31
32 console.log(clName+
33 ": execArgv:["+process.execArgv+"]\n argv:["+process.argv+"]");
34 var taskIdArgstr= process.argv[ 2 ];
35 var CDT_HOME= process.argv[ 3 ];
36 var LOG_DIR= process.argv[ 4 ];
37 console.log( clName+": argv: CDT_HOME:["+CDT_HOME+"]" );
38 var LogF= LOG_DIR+"/ndserver.log";
39 logger.addLog( clName+": start: CDT_HOME:["+CDT_HOME+"]\n",LogF);
40
41 var indT= taskIdArgstr.indexOf('=', 0);
42 if( indT < 0 ) {
43 this.taskId= taskIdArgstr;
44 } else {
45 this.taskId= taskIdArgstr.substr( indT+1 );
46 }
47 console.log(clName+": taskId:["+this.taskId+"]\n");
48 logger.addLog( clName+": taskId:["+this.taskId+"]\n",LogF);
49 if( this.taskId == null || this.taskId == undefined || this.taskId.length < 1 )
50 {
51 var errMsg= clName+": Error: taskId is empty !\n";
52 console.log( errMsg );
53 throw new Error( errMsg );
54 };
55 var inpFilePfx= CDT_HOME+"/posted_data_";
56 var outFilePfx= CDT_HOME+"/sync_template_res_";
57 var parmFilePfx= CDT_HOME+"/template_params_";
58 var pstatfNamePfx= CDT_HOME+"/proc_status_";
59
60 let timeStamp = new Date().toISOString();
61 // console.log(clName+": timeStamp:["+timeStamp+"]\n");
62 logger.addLog( clName+": timeStamp:["+timeStamp+"]\n",LogF);
63
64 var inpFile= inpFilePfx +this.taskId +".txt";
65 // console.log(clName+": deleting inpFile:\n"+inpFile );
66 logger.addLog( clName+": deleting inpFile:\n"+inpFile+"\n",LogF);
67
68 fs.unlink( inpFile, (err) => {
69 if( err) {
70 console.log(clName+
71 ": Error while deleting "+inpFile+"\n "+err.message+"]\n");
72 }
73 });
74
75 timeStamp = new Date().toISOString();
76 console.log(clName+": timeStamp:["+timeStamp+"]\n");
77
78 var pstatfName= pstatfNamePfx +this.taskId+".json";
79 console.log(clName+": deleting proc.status File:\n"+pstatfName );
80
81 fs.unlink( pstatfName, (err) => {
82 if( err) {
83 console.log(clName+
84 ": Error while deleting "+pstatfName+"\n "+err.message+"]\n");
85 }
86 });
87
88 timeStamp = new Date().toISOString();
89 console.log(clName+": timeStamp:["+timeStamp+"]\n");
90
91 var outFile= outFilePfx+ this.taskId+".txt";
92 console.log(clName+": deleting proc.result File:\n"+outFile );
93
94 fs.unlink( outFile, (err) => {
95 if( err) {
96 console.log(clName+
97 ": Error while deleting "+outFile+"\n "+err.message+"]\n");
98 }
99 });
100
101 timeStamp = new Date().toISOString();
102 console.log(clName+": timeStamp:["+timeStamp+"]\n");
103
104 var parmFile= parmFilePfx+ this.taskId+".txt";
105 console.log(clName+": deleting parameters File:\n"+parmFile+"]\n");
106
107 fs.unlink( parmFile, (err) => {
108 if( err) {
109 console.log(clName+
110 ": Error while deleting "+parmFile+"\n "+err.message+"]\n");
111 }
112 });
113
114 timeStamp = new Date().toISOString();
115 console.log(clName+": timeStamp:["+timeStamp+"]\n");
116
117 console.log(clName+": finish.");