@@ -68,6 +68,8 @@ SERVICE_REGISTRATION(Launcher, 1, 0);
6868
6969/* virtual */ const string Launcher::Initialize (PluginHost::IShell* service)
7070{
71+ Time time;
72+ Time interval;
7173 string message;
7274 Config config;
7375
@@ -79,52 +81,42 @@ SERVICE_REGISTRATION(Launcher, 1, 0);
7981
8082 config.FromString (_service->ConfigLine ());
8183
82- _closeTime = (config.CloseTime .Value ());
83-
84- static Core::Process::Options options (config.Command .Value ().c_str ());
85- auto iter = config.Parameters .Elements ();
84+ if (config.ScheduleTime .IsSet () == true ) {
8685
87- while (iter.Next () == true ) {
88- const Config::Parameter& element (iter.Current ());
86+ time = Time (config.ScheduleTime .Time .Value ());
87+ if (time.IsValid () != true ) {
88+ SYSLOG (Trace::Warning, " Interval format is wrong" );
89+ }
8990
90- if ((element.Option .IsSet () == true ) && (element.Option .Value ().empty () == false )) {
91- if ((element.Value .IsSet () == true ) && (element.Value .Value ().empty () == false )) {
92- options.Set (element.Option .Value (), element.Value .Value ());
93- }
94- else {
95- options.Set (element.Option .Value ());
96- }
91+ interval = Time (config.ScheduleTime .Interval .Value ());
92+ if (interval.IsValid () != true ) {
93+ SYSLOG (Trace::Warning, " Interval format is wrong" );
9794 }
95+ printf (" %s:%s:%d %s %s\n " , __FILE__, __func__, __LINE__, time.c_str (), interval.c_str ());
9896 }
9997
100- _options = &options;
98+ _activity = Core::ProxyType<Job>:: Create (&config, interval)
10199
102- if (config.ScheduleTime .IsSet () == true ) {
100+ if (_activity.IsValid () == true ) {
101+ if (_activity->IsOperational () == true ) {
102+ // Well if we where able to parse the parameters (if needed) we are ready to start it..
103+ _observer.Register (&_notification);
103104
104- string time (config.ScheduleTime .Time .Value ());
105- if (time.empty () == false ) {
106- if (_time.Parse (time) != true ) {
107- TRACE_L1 (" Time format is wrong" );
105+ if (_time.Valid () == true ) {
106+ Workerpool::Instance ().Schedule (scheduledTime, _activity);
108107 }
109- }
110-
111- string interval (config.ScheduleTime .Interval .Value ());
112- if (interval.empty () == false ) {
113- if (_interval.Parse (interval) != true ) {
114- TRACE_L1 (" Interval format is wrong" );
108+ else {
109+ Workerpool::Instance ().Submit (_activity);
115110 }
116111 }
117- printf (" %s:%s:%d %s %s\n " , __FILE__, __func__, __LINE__, time.c_str (), interval.c_str ());
112+ else {
113+ message = _T (" Could not parse the configuration for the job." );
114+ }
118115 }
119-
120- _observer.Register (&_notification);
121-
122- // Well if we where able to parse the parameters (if needed) we are ready to start it..
123- bool status = LaunchJob (_time);
124- if (status == false ) {
125- _observer.Unregister (&_notification);
126- message = _T (" Could not spawn the requested app/script [" ) + config.Command .Value () + ' ]' ;
116+ else {
117+ message = _T (" Could not create the job." );
127118 }
119+
128120 return (message);
129121}
130122
@@ -159,48 +151,24 @@ SERVICE_REGISTRATION(Launcher, 1, 0);
159151 return (string ());
160152}
161153
162- bool Launcher::ScheduleJob (Time time)
163- {
164- Core::Time scheduledTime (Core::Time::Now ());
165- uint64_t timeValueToTrigger = ((time.Hour () * 60 + time.Minute ()) * 60 + time.Second ()) * 1000 ;
166-
167- scheduledTime.Add (timeValueToTrigger);
168- PluginHost::WorkerPool::Instance ().Schedule (scheduledTime, _activity);
169- }
170-
171- bool Launcher::LaunchJob (Time time)
172- {
173- bool status = true ;
174- if (time.Hour () == 0 && time.Minute () == 0 && time.Second () == 0 ) {
175- _process.Launch (*_options, &_pid);
176-
177- if (_pid == 0 ) {
178- _observer.Unregister (&_notification);
179- status = false ;
180- }
181- else {
182- _memory = Core::Service<MemoryObserverImpl>::Create<Exchange::IMemory>(_pid);
183- ScheduleJob (_interval);
184- }
185- }
186- else {
187- ScheduleJob (_time);
188- }
189- return status;
190- }
191-
192154void Launcher::Update (const ProcessObserver::Info& info)
193155{
194156 // This can potentially be called on a socket thread, so the deactivation (wich in turn kills this object) must be done
195157 // on a seperate thread. Also make sure this call-stack can be unwound before we are totally destructed.
196- if (_pid == info.Id ()) {
158+ if ((_activity. IsValid () == true ) && (_activity-> Process . Pid () == info.Id ()) {
197159
198160 ASSERT (_service != nullptr );
199161
200162 if (info.Event () == ProcessObserver::Info::EVENT_EXIT) {
201163
202164 if ((info.ExitCode () & 0xFFFF ) == 0 ) {
203- PluginHost::WorkerPool::Instance ().Submit (PluginHost::IShell::Job::Create (_service, PluginHost::IShell::DEACTIVATED, PluginHost::IShell::AUTOMATIC));
165+ // Only do this if we do not need a retrigger on an intervall.
166+ if (_activity->IsOperational () == false ) {
167+ PluginHost::WorkerPool::Instance ().Submit (PluginHost::IShell::Job::Create (_service, PluginHost::IShell::DEACTIVATED, PluginHost::IShell::AUTOMATIC));
168+ }
169+ else {
170+ TRACE (Trace::Information, (_T (" The process has run, and completed succefully." )));
171+ }
204172 }
205173 else {
206174 PluginHost::WorkerPool::Instance ().Submit (PluginHost::IShell::Job::Create (_service, PluginHost::IShell::DEACTIVATED, PluginHost::IShell::FAILURE));
0 commit comments