23
23
#include "agent/pgaStep.h"
24
24
#include "agent/pgaSchedule.h"
26
pgaJob::pgaJob(const wxString& newName)
27
: pgServerObject(jobFactory, newName)
26
pgaJob::pgaJob(const wxString &newName)
27
: pgServerObject(jobFactory, newName)
31
wxString pgaJob::GetTranslatedMessage(int kindOfMessage) const
33
wxString message = wxEmptyString;
35
switch (kindOfMessage)
37
case RETRIEVINGDETAILS:
38
message = _("Retrieving details on pgAgent job");
40
case REFRESHINGDETAILS:
41
message = _("Refreshing pgAgent job");
43
case PROPERTIESREPORT:
44
message = _("pgAgent job properties report");
47
message = _("pgAgent job properties");
49
case DEPENDENCIESREPORT:
50
message = _("pgAgent job dependencies report");
53
message = _("pgAgent job dependencies");
55
case DEPENDENTSREPORT:
56
message = _("pgAgent job dependents report");
59
message = _("pgAgent job dependents");
63
if (!message.IsEmpty())
64
message += wxT(" ") + GetName();
31
69
int pgaJob::GetIconId()
34
return jobFactory.GetIconId();
36
return jobFactory.GetDisabledId();
72
return jobFactory.GetIconId();
74
return jobFactory.GetDisabledId();
40
78
wxMenu *pgaJob::GetNewMenu()
42
wxMenu *menu=pgObject::GetNewMenu();
45
stepFactory.AppendMenu(menu);
46
scheduleFactory.AppendMenu(menu);
80
wxMenu *menu = pgObject::GetNewMenu();
83
stepFactory.AppendMenu(menu);
84
scheduleFactory.AppendMenu(menu);
52
90
bool pgaJob::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
54
return GetConnection()->ExecuteVoid(wxT("DELETE FROM pgagent.pga_job WHERE jobid=") + NumToStr(GetRecId()));
92
return GetConnection()->ExecuteVoid(wxT("DELETE FROM pgagent.pga_job WHERE jobid=") + NumToStr(GetRecId()));
58
96
void pgaJob::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
64
browser->RemoveDummyChild(this);
67
wxLogInfo(wxT("Adding child objects to Job."));
69
browser->AppendCollection(this, scheduleFactory);
70
browser->AppendCollection(this, stepFactory);
75
CreateListColumns(properties);
77
properties->AppendItem(_("Name"), GetName());
78
properties->AppendItem(_("ID"), GetRecId());
79
properties->AppendItem(_("Enabled"), GetEnabled());
102
browser->RemoveDummyChild(this);
105
wxLogInfo(wxT("Adding child objects to Job."));
107
browser->AppendCollection(this, scheduleFactory);
108
browser->AppendCollection(this, stepFactory);
113
CreateListColumns(properties);
115
properties->AppendItem(_("Name"), GetName());
116
properties->AppendItem(_("ID"), GetRecId());
117
properties->AppendYesNoItem(_("Enabled"), GetEnabled());
80
118
properties->AppendItem(_("Host agent"), GetHostAgent());
81
properties->AppendItem(_("Job class"), GetJobclass());
82
properties->AppendItem(_("Created"), GetCreated());
83
properties->AppendItem(_("Changed"), GetChanged());
84
properties->AppendItem(_("Next run"), GetNextrun());
85
properties->AppendItem(_("Last run"), GetLastrun());
86
properties->AppendItem(_("Last result"), GetLastresult());
119
properties->AppendItem(_("Job class"), GetJobclass());
120
properties->AppendItem(_("Created"), GetCreated());
121
properties->AppendItem(_("Changed"), GetChanged());
122
properties->AppendItem(_("Next run"), GetNextrun());
123
properties->AppendItem(_("Last run"), GetLastrun());
124
properties->AppendItem(_("Last result"), GetLastresult());
87
125
if (!GetCurrentAgent().IsEmpty())
88
126
properties->AppendItem(_("Running at"), GetCurrentAgent());
90
128
properties->AppendItem(_("Running at"), _("Not currently running"));
92
properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));
130
properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));
98
136
pgObject *pgaJob::Refresh(ctlTree *browser, const wxTreeItemId item)
102
pgObject *obj=browser->GetObject(browser->GetItemParent(item));
103
if (obj->IsCollection())
104
job = jobFactory.CreateObjects((pgCollection*)obj, 0, wxT("\n WHERE j.jobid=") + NumToStr(GetRecId()));
140
pgObject *obj = browser->GetObject(browser->GetItemParent(item));
141
if (obj->IsCollection())
142
job = jobFactory.CreateObjects((pgCollection *)obj, 0, wxT("\n WHERE j.jobid=") + NumToStr(GetRecId()));
111
149
pgObject *pgaJobFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction)
115
pgSet *jobs= collection->GetConnection()->ExecuteSet(
116
wxT("SELECT j.*, cl.*, ag.*, sub.jlgstatus AS joblastresult ")
117
wxT(" FROM pgagent.pga_job j JOIN")
118
wxT(" pgagent.pga_jobclass cl ON cl.jclid=jobjclid LEFT OUTER JOIN")
119
wxT(" pgagent.pga_jobagent ag ON ag.jagpid=jobagentid LEFT OUTER JOIN")
120
wxT(" (SELECT DISTINCT ON (jlgjobid) jlgstatus, jlgjobid")
121
wxT(" FROM pgagent.pga_joblog")
122
wxT(" ORDER BY jlgjobid, jlgid desc) sub ON sub.jlgjobid = j.jobid ")
124
wxT("ORDER BY jobname;"));
153
pgSet *jobs = collection->GetConnection()->ExecuteSet(
154
wxT("SELECT j.*, cl.*, ag.*, sub.jlgstatus AS joblastresult ")
155
wxT(" FROM pgagent.pga_job j JOIN")
156
wxT(" pgagent.pga_jobclass cl ON cl.jclid=jobjclid LEFT OUTER JOIN")
157
wxT(" pgagent.pga_jobagent ag ON ag.jagpid=jobagentid LEFT OUTER JOIN")
158
wxT(" (SELECT DISTINCT ON (jlgjobid) jlgstatus, jlgjobid")
159
wxT(" FROM pgagent.pga_joblog")
160
wxT(" ORDER BY jlgjobid, jlgid desc) sub ON sub.jlgjobid = j.jobid ")
162
wxT("ORDER BY jobname;"));
131
169
if (jobs->GetVal(wxT("joblastresult")) == wxT("r"))
132
status = _("Running");
133
else if (jobs->GetVal(wxT("joblastresult")) == wxT("s"))
134
status = _("Successful");
170
status = _("Running");
171
else if (jobs->GetVal(wxT("joblastresult")) == wxT("s"))
172
status = _("Successful");
135
173
else if (jobs->GetVal(wxT("joblastresult")) == wxT("f"))
136
status = _("Failed");
174
status = _("Failed");
137
175
else if (jobs->GetVal(wxT("joblastresult")) == wxT("d"))
138
status = _("Aborted");
139
else if (jobs->GetVal(wxT("joblastresult")) == wxT("i"))
140
status = _("No steps");
176
status = _("Aborted");
177
else if (jobs->GetVal(wxT("joblastresult")) == wxT("i"))
178
status = _("No steps");
142
status = _("Unknown");
144
job = new pgaJob(jobs->GetVal(wxT("jobname")));
145
job->iSetServer(collection->GetServer());
146
job->iSetRecId(jobs->GetLong(wxT("jobid")));
147
job->iSetComment(jobs->GetVal(wxT("jobdesc")));
149
job->iSetEnabled(jobs->GetBool(wxT("jobenabled")));
150
job->iSetJobclass(jobs->GetVal(wxT("jclname")));
180
status = _("Unknown");
182
job = new pgaJob(jobs->GetVal(wxT("jobname")));
183
job->iSetServer(collection->GetServer());
184
job->iSetRecId(jobs->GetLong(wxT("jobid")));
185
job->iSetComment(jobs->GetVal(wxT("jobdesc")));
187
job->iSetEnabled(jobs->GetBool(wxT("jobenabled")));
188
job->iSetJobclass(jobs->GetVal(wxT("jclname")));
151
189
job->iSetHostAgent(jobs->GetVal(wxT("jobhostagent")));
152
job->iSetCreated(jobs->GetDateTime(wxT("jobcreated")));
153
job->iSetChanged(jobs->GetDateTime(wxT("jobchanged")));
154
job->iSetNextrun(jobs->GetDateTime(wxT("jobnextrun")));
155
job->iSetLastrun(jobs->GetDateTime(wxT("joblastrun")));
156
job->iSetLastresult(status);
190
job->iSetCreated(jobs->GetDateTime(wxT("jobcreated")));
191
job->iSetChanged(jobs->GetDateTime(wxT("jobchanged")));
192
job->iSetNextrun(jobs->GetDateTime(wxT("jobnextrun")));
193
job->iSetLastrun(jobs->GetDateTime(wxT("joblastrun")));
194
job->iSetLastresult(status);
157
195
job->iSetCurrentAgent(jobs->GetVal(wxT("jagstation")));
161
browser->AppendObject(collection, job);
199
browser->AppendObject(collection, job);
162
200
jobs->MoveNext();
173
211
void pgaJob::ShowStatistics(frmMain *form, ctlListView *statistics)
180
wxT(", (jlgstart + jlgduration) AS endtime")
181
wxT(" FROM pgagent.pga_joblog\n")
182
wxT(" WHERE jlgjobid = ") + NumToStr(GetRecId()) +
183
wxT(" ORDER BY jlgstart DESC") +
184
wxT(" LIMIT ") + NumToStr(settings->GetMaxRows());
188
wxLogInfo(wxT("Displaying statistics for job %s"), GetFullIdentifier().c_str());
190
// Add the statistics view columns
218
wxT(", (jlgstart + jlgduration) AS endtime")
219
wxT(" FROM pgagent.pga_joblog\n")
220
wxT(" WHERE jlgjobid = ") + NumToStr(GetRecId()) +
221
wxT(" ORDER BY jlgstart DESC") +
222
wxT(" LIMIT ") + NumToStr(settings->GetMaxRows());
226
wxLogInfo(wxT("Displaying statistics for job %s"), GetFullIdentifier().c_str());
228
// Add the statistics view columns
191
229
statistics->ClearAll();
192
230
statistics->AddColumn(_("Run"), 50);
193
statistics->AddColumn(_("Status"), 60);
231
statistics->AddColumn(_("Status"), 60);
194
232
statistics->AddColumn(_("Start time"), 95);
195
233
statistics->AddColumn(_("End time"), 95);
196
234
statistics->AddColumn(_("Duration"), 70);
198
pgSet *stats = GetConnection()->ExecuteSet(sql);
236
pgSet *stats = GetConnection()->ExecuteSet(sql);
200
238
wxDateTime startTime;
201
239
wxDateTime endTime;
205
while (!stats->Eof())
243
while (!stats->Eof())
207
245
if (stats->GetVal(1) == wxT("r"))
208
status = _("Running");
246
status = _("Running");
209
247
else if (stats->GetVal(1) == wxT("s"))
210
status = _("Successful");
248
status = _("Successful");
211
249
else if (stats->GetVal(1) == wxT("f"))
212
status = _("Failed");
250
status = _("Failed");
213
251
else if (stats->GetVal(1) == wxT("d"))
214
status = _("Aborted");
252
status = _("Aborted");
215
253
else if (stats->GetVal(1) == wxT("i"))
216
status = _("No steps");
254
status = _("No steps");
218
status = _("Unknown");
256
status = _("Unknown");
220
258
startTime.ParseDateTime(stats->GetVal(2));
221
259
endTime.ParseDateTime(stats->GetVal(4));
223
long pos=statistics->AppendItem(stats->GetVal(0), status, startTime.Format());
261
long pos = statistics->AppendItem(stats->GetVal(0), status, startTime.Format());
224
262
if (stats->GetVal(4).Length() > 0)
225
statistics->SetItem(pos, 3, endTime.Format());
263
statistics->SetItem(pos, 3, endTime.Format());
226
264
statistics->SetItem(pos, 4, stats->GetVal(3));
228
266
stats->MoveNext();
235
273
bool pgaJob::RunNow()
237
if (!GetConnection()->ExecuteVoid(wxT("UPDATE pgagent.pga_job SET jobnextrun = now() WHERE jobid=") + NumToStr(GetRecId())))
275
if (!GetConnection()->ExecuteVoid(wxT("UPDATE pgagent.pga_job SET jobnextrun = now() WHERE jobid=") + NumToStr(GetRecId())))
243
pgaJobObject::pgaJobObject(pgaJob *_job, pgaFactory &factory, const wxString& newName)
244
: pgServerObject(factory, newName)
281
pgaJobObject::pgaJobObject(pgaJob *_job, pgaFactory &factory, const wxString &newName)
282
: pgServerObject(factory, newName)
247
server=job->GetServer();
285
server = job->GetServer();
251
289
pgaJobObjCollection::pgaJobObjCollection(pgaFactory *factory, pgaJob *_job)
252
: pgServerObjCollection(factory, _job->GetServer())
290
: pgServerObjCollection(factory, _job->GetServer())
258
296
bool pgaJobObjCollection::CanCreate()
260
return job->CanCreate();
298
return job->CanCreate();
264
302
pgCollection *pgaJobObjFactory::CreateCollection(pgObject *obj)
266
return new pgaJobObjCollection(GetCollectionFactory(), (pgaJob*)obj);
271
#include "images/job.xpm"
272
#include "images/jobs.xpm"
273
#include "images/jobdisabled.xpm"
275
pgaJobFactory::pgaJobFactory()
276
: pgServerObjFactory(__("pgAgent Job"), __("New Job"), __("Create a new Job."), job_xpm)
279
disabledId = addIcon(jobdisabled_xpm);
304
return new pgaJobObjCollection(GetCollectionFactory(), (pgaJob *)obj);
308
wxString pgaJobObjCollection::GetTranslatedMessage(int kindOfMessage) const
310
wxString message = wxEmptyString;
312
switch (kindOfMessage)
314
case RETRIEVINGDETAILS:
315
message = _("Retrieving details on pgAgent jobs");
317
case REFRESHINGDETAILS:
318
message = _("Refreshing pgAgent jobs");
325
/////////////////////////////
328
#include "images/job.pngc"
329
#include "images/jobs.pngc"
330
#include "images/jobdisabled.pngc"
332
pgaJobFactory::pgaJobFactory()
333
: pgServerObjFactory(__("pgAgent Job"), __("New Job"), __("Create a new Job."), job_png_img)
336
disabledId = addIcon(jobdisabled_png_img);
283
340
pgaJobFactory jobFactory;
284
static pgaCollectionFactory cf(&jobFactory, __("Jobs"), jobs_xpm);
341
static pgaCollectionFactory cf(&jobFactory, __("Jobs"), jobs_png_img);
286
343
runNowFactory::runNowFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : contextActionFactory(list)
288
mnu->Append(id, _("&Run now"), _("Reschedule the job to run now."));
345
mnu->Append(id, _("&Run now"), _("Reschedule the job to run now."));
292
349
wxWindow *runNowFactory::StartDialog(frmMain *form, pgObject *obj)
294
if (!((pgaJob *)(obj))->RunNow())
295
wxLogError(_("Failed to reschedule the job."));
351
if (!((pgaJob *)(obj))->RunNow())
353
wxLogError(_("Failed to reschedule the job."));
303
362
bool runNowFactory::CheckEnable(pgObject *obj)
307
if (obj->GetMetaType() == PGM_JOB && !obj->IsCollection())
366
if (obj->GetMetaType() == PGM_JOB && !obj->IsCollection())