Register backup to task service for execution (#381)

* Create backup task for execution

* Register backup to task service

* Fix backup task service

* Fix async methods

* Add backup unit test

* Add cancellation token to task service and fix other PR comments

* Add SR and fix other pr comments

* Add comments to methods

* Fixed backup cancel test and casing

* Change sleep time in test
This commit is contained in:
Kate Shin
2017-06-16 14:01:09 -07:00
committed by GitHub
parent 0c7533b5b9
commit a646d627c6
22 changed files with 14122 additions and 7482 deletions

View File

@@ -10,6 +10,7 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.TaskServices.Contracts;
using Microsoft.SqlTools.Utility;
using System.Threading;
namespace Microsoft.SqlTools.ServiceLayer.TaskServices
{
@@ -37,18 +38,24 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
/// Creates new instance of SQL task
/// </summary>
/// <param name="taskMetdata">Task Metadata</param>
/// <param name="testToRun">The function to run to start the task</param>
public SqlTask(TaskMetadata taskMetdata, Func<SqlTask, Task<TaskResult>> testToRun)
/// <param name="taskToRun">The function to run to start the task</param>
public SqlTask(TaskMetadata taskMetdata, Func<SqlTask, Task<TaskResult>> taskToRun)
{
Validate.IsNotNull(nameof(taskMetdata), taskMetdata);
Validate.IsNotNull(nameof(testToRun), testToRun);
Validate.IsNotNull(nameof(taskToRun), taskToRun);
TaskMetadata = taskMetdata;
TaskToRun = testToRun;
TaskToRun = taskToRun;
StartTime = DateTime.UtcNow;
TaskId = Guid.NewGuid();
TokenSource = new CancellationTokenSource();
}
/// <summary>
/// Cancellation token
/// </summary>
public CancellationTokenSource TokenSource { get; private set; }
/// <summary>
/// Task Metadata
/// </summary>
@@ -99,9 +106,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
//Run Task synchronously
public void Run()
{
RunAsync().ContinueWith(task =>
{
});
Task.Run(() => RunAsync());
}
/// <summary>
@@ -254,7 +259,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
}
/// <summary>
/// Try to cancel the task, and even to cancel the task will be raised
/// Try to cancel the task, and event to cancel the task will be raised
/// but the status won't change until that task actually get canceled by it's owner
/// </summary>
public void Cancel()
@@ -376,6 +381,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
private void OnTaskCancelRequested()
{
TokenSource.Cancel();
var handler = TaskCanceled;
if (handler != null)
{
@@ -387,10 +393,9 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
{
//Dispose
isDisposed = true;
TokenSource.Dispose();
}
protected void ValidateNotDisposed()
{
if (isDisposed)

View File

@@ -133,6 +133,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
Status = e.TaskData
};
if (sqlTask.IsCompleted)
{
progressInfo.Duration = sqlTask.Duration;
@@ -149,7 +150,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
TaskProgressInfo progressInfo = new TaskProgressInfo
{
TaskId = sqlTask.TaskId.ToString(),
Message = e.TaskData.Description
Message = e.TaskData.Description,
Status = sqlTask.TaskStatus
};
await serviceHost.SendEvent(TaskStatusChangedNotification.Type, progressInfo);
}