using namespace std;
using namespace Batch;
+const int MAX_SLEEP_TIME = 600;
+
int main(int argc, char** argv)
{
cout << "*******************************************************************************************" << endl;
job.setParametre(p);
// ... and its environment
Environnement e;
+ e["MYENVVAR"] = "MYVALUE";
job.setEnvironnement(e);
cout << job << endl;
cout << jobid.__repr__() << endl;
// Wait for the end of the job
- string state = "Undefined";
- for (int i=0 ; i<timeout/2 && state != "U" && state != "C"; i++) {
- sleep(2);
- JobInfo jinfo = jobid.queryJob();
+ int time = 0;
+ int sleeptime = 1;
+ bool testTimeout = (timeout > -1);
+ bool timeoutReached = (testTimeout && time >= timeout);
+ JobInfo jinfo = jobid.queryJob();
+ string state = jinfo.getParametre()["STATE"].str();
+ cout << "State is \"" << state << "\"";
+ while (!timeoutReached && state != "U" && state != "C") {
+ cout << ", sleeping " << sleeptime << "s..." << endl;
+ sleep(sleeptime);
+ time += sleeptime;
+ timeoutReached = (testTimeout && time >= timeout);
+ sleeptime *= 2;
+ if (testTimeout && sleeptime > timeout - time)
+ sleeptime = timeout - time;
+ if (sleeptime > MAX_SLEEP_TIME)
+ sleeptime = MAX_SLEEP_TIME;
+ jinfo = jobid.queryJob();
state = jinfo.getParametre()["STATE"].str();
- cout << "State is \"" << state << "\"" << endl;
+ cout << "State is \"" << state << "\"";
}
+ cout << endl;
if (state == "U" || state == "C") {
cout << "Job " << jobid.__repr__() << " is done" << endl;
}
// test the result file
- string exp = "c = 12";
- string res;
- ifstream f("result.txt");
- getline(f, res);
- f.close();
-
- cout << "result found : " << res << ", expected : " << exp << endl;
-
- if (res == exp)
- return 0;
- else
+ try {
+ SimpleParser resultParser;
+ resultParser.parse("result.txt");
+ cout << "Result:" << endl << resultParser;
+ const string & envvar = resultParser.getValue("MYENVVAR");
+ int result = resultParser.getValueAsInt("c");
+ if (envvar == "MYVALUE" && result == 12) {
+ cout << "OK, Expected result found." << endl;
+ return 0;
+ } else {
+ cerr << "Error, result is not the expected one (MYENVVAR = MYVALUE, c = 12)." << endl;
+ return 1;
+ }
+ } catch (ParserException e) {
+ cerr << "Parser error on result file: " << e.what() << endl;
return 1;
+ }
}