Skip to content

Commit

Permalink
Add unassign job route (#34814)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamzhao87 authored Mar 9, 2023
1 parent 78d3c46 commit c3aa137
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ public RouterClient(System.Uri endpoint, Azure.Core.TokenCredential credential,
public virtual Azure.AsyncPageable<Azure.Communication.JobRouter.Models.RouterWorkerItem> GetWorkersAsync(Azure.Communication.JobRouter.GetWorkersOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.JobRouter.Models.ReclassifyJobResult> ReclassifyJob(string jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.JobRouter.Models.ReclassifyJobResult>> ReclassifyJobAsync(string jobId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.JobRouter.Models.UnassignJobResult> UnassignJob(Azure.Communication.JobRouter.UnassignJobOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.JobRouter.Models.UnassignJobResult>> UnassignJobAsync(Azure.Communication.JobRouter.UnassignJobOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.JobRouter.Models.RouterJob> UpdateJob(Azure.Communication.JobRouter.UpdateJobOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.JobRouter.Models.RouterJob>> UpdateJobAsync(Azure.Communication.JobRouter.UpdateJobOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.JobRouter.Models.RouterWorker> UpdateWorker(Azure.Communication.JobRouter.UpdateWorkerOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down Expand Up @@ -444,6 +446,12 @@ public partial class StaticWorkerSelectorAttachment : Azure.Communication.JobRou
public StaticWorkerSelectorAttachment(Azure.Communication.JobRouter.WorkerSelector labelSelector) { }
public Azure.Communication.JobRouter.WorkerSelector LabelSelector { get { throw null; } set { } }
}
public partial class UnassignJobOptions
{
public UnassignJobOptions(string jobId, string assignmentId) { }
public string AssignmentId { get { throw null; } }
public string JobId { get { throw null; } }
}
public partial class UpdateClassificationPolicyOptions
{
public UpdateClassificationPolicyOptions(string classificationPolicyId) { }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#nullable enable
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
using Azure.Core;

namespace Azure.Communication.JobRouter
{
/// <summary>
/// Options for unassigning a job.
/// </summary>
public class UnassignJobOptions
{
/// <summary>
/// Public constructor.
/// </summary>
/// <param name="jobId"> Id of the job. </param>
/// <param name="assignmentId"> Id of the assignment. </param>
/// <exception cref="ArgumentNullException"> <paramref name="jobId"/> is null. </exception>
/// <exception cref="ArgumentNullException"> <paramref name="assignmentId"/> is null. </exception>
public UnassignJobOptions(string jobId, string assignmentId)
{
Argument.AssertNotNullOrWhiteSpace(jobId, nameof(jobId));
Argument.AssertNotNullOrWhiteSpace(assignmentId, nameof(assignmentId));

JobId = jobId;
AssignmentId = assignmentId;
}

/// <summary>
/// Unique key that identifies this job.
/// </summary>
public string JobId { get; }

/// <summary>
/// Unique key that identifies this job assignment.
/// </summary>
public string AssignmentId { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,55 @@ public virtual Response<RouterWorker> UpdateWorker(
}
}

/// <summary> Unassign a job from a worker. </summary>
/// <param name="options"> Options for unassigning a job from a worker. </param>
/// <param name="cancellationToken"> (Optional) The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual async Task<Response<UnassignJobResult>> UnassignJobAsync(UnassignJobOptions options, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(RouterClient)}.{nameof(UnassignJobAsync)}");
scope.Start();
try
{
var response = await RestClient.UnassignJobActionAsync(
id: options.JobId,
assignmentId: options.AssignmentId,
cancellationToken: cancellationToken)
.ConfigureAwait(false);

return Response.FromValue(response.Value, response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary> Unassign a job from a worker. </summary>
/// <param name="options"> Options for unassigning a job from a worker. </param>
/// <param name="cancellationToken"> (Optional) The cancellation token to use. </param>
/// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
public virtual Response<UnassignJobResult> UnassignJob(UnassignJobOptions options, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(RouterClient)}.{nameof(UnassignJob)}");
scope.Start();
try
{
var response = RestClient.UnassignJobAction(
id: options.JobId,
assignmentId: options.AssignmentId,
cancellationToken: cancellationToken);

return Response.FromValue(response.Value, response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary> Retrieves existing workers. Pass status and Channel Id to filter workers further. </summary>
/// <param name="options"> Options for filtering while retrieving router workers. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
Expand Down

0 comments on commit c3aa137

Please sign in to comment.