Agent/improvements (#720)

* add steps and schedules to edit job

* added alerts to edit data logic

* fixed c# style
This commit is contained in:
Aditya Bist
2018-10-31 16:40:17 -07:00
committed by GitHub
parent 6153279840
commit 4f148a583b
2 changed files with 66 additions and 7 deletions

View File

@@ -882,7 +882,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
ConfigAction configAction,
RunType runType)
{
return await Task<Tuple<bool, string>>.Run(() =>
return await Task<Tuple<bool, string>>.Run(async () =>
{
try
{
@@ -895,6 +895,34 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
ExecuteAction(actions, runType);
}
// Execute step actions if they exist
if (jobInfo.JobSteps != null && jobInfo.JobSteps.Length > 0)
{
foreach (AgentJobStepInfo step in jobInfo.JobSteps)
{
await ConfigureAgentJobStep(ownerUri, step, configAction, runType);
}
}
// Execute schedule actions if they exist
if (jobInfo.JobSchedules != null && jobInfo.JobSchedules.Length > 0)
{
foreach (AgentScheduleInfo schedule in jobInfo.JobSchedules)
{
await ConfigureAgentSchedule(ownerUri, schedule, configAction, runType);
}
}
// Execute alert actions if they exist
if (jobInfo.Alerts != null && jobInfo.Alerts.Length > 0)
{
foreach (AgentAlertInfo alert in jobInfo.Alerts)
{
alert.JobId = jobData.Job.JobID.ToString();
await ConfigureAgentAlert(ownerUri, alert.Name, alert, configAction, runType);
}
}
return new Tuple<bool, string>(true, string.Empty);
}
catch (Exception ex)
@@ -949,15 +977,25 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
{
try
{
ConnectionInfo connInfo;
ConnectionServiceInstance.TryFindConnection(ownerUri, out connInfo);
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
CDataContainer dataContainer;
JobData jobData = null;
// If the alert is being created outside of a job
if (string.IsNullOrWhiteSpace(alert.JobName))
{
ConnectionInfo connInfo;
ConnectionServiceInstance.TryFindConnection(ownerUri, out connInfo);
dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
}
else
{
// If the alert is being created inside a job
CreateJobData(ownerUri, alert.JobName, out dataContainer, out jobData);
}
STParameters param = new STParameters(dataContainer.Document);
param.SetParam("alert", alertName);
if (alert != null)
{
using (AgentAlertActions actions = new AgentAlertActions(dataContainer, alertName, alert, configAction))
using (AgentAlertActions actions = new AgentAlertActions(dataContainer, alertName, alert, configAction, jobData))
{
ExecuteAction(actions, runType);
}