Example #1
0
	void runOnceOnlyTest() 
	{
		json::Value json;

		// Schedule a once only task to run in 5 seconds time.
		{
			ScheduledTask* task = new ScheduledTask(); //scheduler
			OnceOnlyTrigger* trigger = task->createTrigger<OnceOnlyTrigger>();
			
			DateTime dt;
			Timespan ts(2, 0);
			dt += ts;
			trigger->scheduleAt = dt;
			assert(ts.seconds() == 2);
			
			scheduler.start(task);
			
			// Serialize the task
			scheduler.serialize(json);

			// Wait for the task to complete
			app.run();
		}	
			
		// Deserialize the previous task from JSON and run it again
		{	
			// Set the task to run in 1 secs time
			{				
				DateTime dt;
				Timespan ts(1, 0);
				dt += ts;
				json[(size_t)0]["trigger"]["scheduleAt"] = 
					DateTimeFormatter::format(dt, DateTimeFormat::ISO8601_FORMAT);
			}

			// Dynamically create the task from JSON
			Log("debug") << "Sked Input JSON:\n" 
				<< json::stringify(json, true) << endl;
			scheduler.deserialize(json);

			// Print to cout
			Log("debug") << "##### Sked Print Output:" << endl;
			scheduler.print(cout);
			Log("debug") << "##### Sked Print Output END" << endl;
			
			// Output scheduler tasks as JSON before run
			json::Value before;
			scheduler.serialize(before);
			Log("debug") << "Sked Output JSON Before Run:\n" 
				<< json::stringify(before, true) << endl;
			
			// Wait for the task to complete
			app.run();
			
			// Output scheduler tasks as JSON after run
			json::Value after;
			scheduler.serialize(after);
			Log("debug") << "Sked Output JSON After Run:\n" 
				<< json::stringify(after, true) << endl;
		}
	}