Skip to content

Commit

Permalink
Added more functionality to Turnout
Browse files Browse the repository at this point in the history
  • Loading branch information
phatboyg committed Jun 15, 2016
1 parent 75686b1 commit 9e9b140
Show file tree
Hide file tree
Showing 16 changed files with 257 additions and 18 deletions.
31 changes: 31 additions & 0 deletions src/MassTransit/Exceptions/JobNotFoundException.cs
@@ -0,0 +1,31 @@
// Copyright 2007-2016 Chris Patterson, Dru Sellers, Travis Smith, et. al.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
namespace MassTransit
{
using System;


[Serializable]
public class JobNotFoundException :
MassTransitException
{
public JobNotFoundException()
{
}

public JobNotFoundException(string message)
: base(message)
{
}
}
}
5 changes: 5 additions & 0 deletions src/MassTransit/MassTransit.csproj
Expand Up @@ -230,6 +230,7 @@
<Compile Include="Exceptions\CommandException.cs" />
<Compile Include="Exceptions\ContextException.cs" />
<Compile Include="Exceptions\JobAlreadyExistsException.cs" />
<Compile Include="Exceptions\JobNotFoundException.cs" />
<Compile Include="Exceptions\MessageDataException.cs" />
<Compile Include="Exceptions\MessageDataNotFoundException.cs" />
<Compile Include="Hosting\ConfigurationProviderExtensions.cs" />
Expand Down Expand Up @@ -975,10 +976,14 @@
<Compile Include="Transformation\Contexts\SendTransformContext.cs" />
<Compile Include="Transformation\TransformConfigurators\SendTransformSpecification.cs" />
<Compile Include="Transformation\TransformConfigurators\TransformSpecification.cs" />
<Compile Include="Turnout\CancelJobConsumer.cs" />
<Compile Include="Turnout\Commands\Supervise.cs" />
<Compile Include="Turnout\Configuration\ITurnoutHostConfigurator.cs" />
<Compile Include="Turnout\Configuration\TurnoutHostSpecification.cs" />
<Compile Include="Turnout\Contracts\CancelJob.cs" />
<Compile Include="Turnout\Contracts\JobCanceled.cs" />
<Compile Include="Turnout\Contracts\MonitorJob.cs" />
<Compile Include="Turnout\Events\Canceled.cs" />
<Compile Include="Turnout\Events\Completed.cs" />
<Compile Include="Turnout\Events\Faulted.cs" />
<Compile Include="Turnout\SuperviseJobConsumer.cs" />
Expand Down
42 changes: 42 additions & 0 deletions src/MassTransit/Turnout/CancelJobConsumer.cs
@@ -0,0 +1,42 @@
// Copyright 2007-2016 Chris Patterson, Dru Sellers, Travis Smith, et. al.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
namespace MassTransit.Turnout
{
using System.Threading.Tasks;
using Contracts;


/// <summary>
/// The consumer that handles the control messages for the job
/// </summary>
public class CancelJobConsumer :
IConsumer<CancelJob>

{
readonly IJobRoster _roster;

public CancelJobConsumer(IJobRoster roster)
{
_roster = roster;
}

public async Task Consume(ConsumeContext<CancelJob> context)
{
JobHandle jobHandle;
if (!_roster.TryGetJob(context.Message.JobId, out jobHandle))
throw new JobNotFoundException($"The JobId {context.Message.JobId} was not found.");

await jobHandle.Cancel().ConfigureAwait(false);
}
}
}
2 changes: 1 addition & 1 deletion src/MassTransit/Turnout/ConsumerJobHandle.cs
@@ -1,4 +1,4 @@
// Copyright 2007-2015 Chris Patterson, Dru Sellers, Travis Smith, et. al.
// Copyright 2007-2016 Chris Patterson, Dru Sellers, Travis Smith, et. al.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
Expand Down
35 changes: 35 additions & 0 deletions src/MassTransit/Turnout/Contracts/CancelJob.cs
@@ -0,0 +1,35 @@
// Copyright 2007-2016 Chris Patterson, Dru Sellers, Travis Smith, et. al.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
namespace MassTransit.Turnout.Contracts
{
using System;


public interface CancelJob
{
/// <summary>
/// The job identifier
/// </summary>
Guid JobId { get; }

/// <summary>
/// The time the job was started
/// </summary>
DateTime Timestamp { get; }

/// <summary>
/// The reason for cancelling the job
/// </summary>
string Reason { get; }
}
}
47 changes: 47 additions & 0 deletions src/MassTransit/Turnout/Contracts/JobCanceled.cs
@@ -0,0 +1,47 @@
// Copyright 2007-2016 Chris Patterson, Dru Sellers, Travis Smith, et. al.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
namespace MassTransit.Turnout.Contracts
{
using System;


/// <summary>
/// Published when a job faults
/// </summary>
/// <typeparam name="TInput"></typeparam>
public interface JobCanceled<out TInput> :
JobCanceled
{
/// <summary>
/// The job input
/// </summary>
TInput Input { get; }
}


/// <summary>
/// Published when a job faults
/// </summary>
public interface JobCanceled
{
/// <summary>
/// The job identifier
/// </summary>
Guid JobId { get; }

/// <summary>
/// The time the job was cancelled
/// </summary>
DateTime Timestamp { get; }
}
}
10 changes: 5 additions & 5 deletions src/MassTransit/Turnout/Contracts/JobCompleted.cs
@@ -1,4 +1,4 @@
// Copyright 2007-2015 Chris Patterson, Dru Sellers, Travis Smith, et. al.
// Copyright 2007-2016 Chris Patterson, Dru Sellers, Travis Smith, et. al.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
Expand Down Expand Up @@ -35,14 +35,14 @@ public interface JobCompleted
/// <summary>
/// Published when a job completes with a result
/// </summary>
/// <typeparam name="T"></typeparam>
public interface JobCompleted<out T> :
/// <typeparam name="TResult"></typeparam>
public interface JobCompleted<out TResult> :
JobCompleted
where T : class
where TResult : class
{
/// <summary>
/// The result of the job
/// </summary>
T Result { get; }
TResult Result { get; }
}
}
13 changes: 13 additions & 0 deletions src/MassTransit/Turnout/Contracts/JobFaulted.cs
Expand Up @@ -35,4 +35,17 @@ public interface JobFaulted
/// </summary>
ExceptionInfo Exceptions { get; }
}

/// <summary>
/// Published when a job faults
/// </summary>
/// <typeparam name="TInput"></typeparam>
public interface JobFaulted<out TInput> :
JobFaulted
{
/// <summary>
/// The job input
/// </summary>
TInput Input { get; }
}
}
7 changes: 4 additions & 3 deletions src/MassTransit/Turnout/CreateJobConsumer.cs
@@ -1,4 +1,4 @@
// Copyright 2007-2015 Chris Patterson, Dru Sellers, Travis Smith, et. al.
// Copyright 2007-2016 Chris Patterson, Dru Sellers, Travis Smith, et. al.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
Expand All @@ -14,6 +14,7 @@ namespace MassTransit.Turnout
{
using System.Threading.Tasks;


/// <summary>
/// The consumer that creates the job using the turnout host
/// </summary>
Expand All @@ -23,8 +24,8 @@ public class CreateJobConsumer<T> :
where T : class

{
readonly ITurnoutController _turnoutHost;
readonly IJobFactory<T> _jobFactory;
readonly ITurnoutController _turnoutHost;

public CreateJobConsumer(ITurnoutController turnoutHost, IJobFactory<T> jobFactory)
{
Expand All @@ -34,7 +35,7 @@ public CreateJobConsumer(ITurnoutController turnoutHost, IJobFactory<T> jobFacto

public async Task Consume(ConsumeContext<T> context)
{
var job = await _turnoutHost.CreateJob(context, _jobFactory).ConfigureAwait(false);
JobHandle<T> job = await _turnoutHost.CreateJob(context, _jobFactory).ConfigureAwait(false);
}
}
}
2 changes: 1 addition & 1 deletion src/MassTransit/Turnout/DelegateJobFactory.cs
@@ -1,4 +1,4 @@
// Copyright 2007-2015 Chris Patterson, Dru Sellers, Travis Smith, et. al.
// Copyright 2007-2016 Chris Patterson, Dru Sellers, Travis Smith, et. al.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
Expand Down
33 changes: 33 additions & 0 deletions src/MassTransit/Turnout/Events/Canceled.cs
@@ -0,0 +1,33 @@
// Copyright 2007-2016 Chris Patterson, Dru Sellers, Travis Smith, et. al.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
namespace MassTransit.Turnout.Events
{
using System;
using Contracts;


class Canceled<TInput> :
JobCanceled<TInput>
{
public Canceled(Guid jobId, TInput input)
{
JobId = jobId;
Input = input;
Timestamp = DateTime.UtcNow;
}

public Guid JobId { get; }
public DateTime Timestamp { get; }
public TInput Input { get; }
}
}
20 changes: 17 additions & 3 deletions src/MassTransit/Turnout/Events/Faulted.cs
@@ -1,22 +1,36 @@
// Copyright 2007-2016 Chris Patterson, Dru Sellers, Travis Smith, et. al.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
namespace MassTransit.Turnout.Events
{
using System;
using Contracts;
using MassTransit.Events;


class Faulted :
JobFaulted
class Faulted<TInput> :
JobFaulted<TInput>
{
public Faulted(Guid jobId, Exception exception)
public Faulted(Guid jobId, TInput input, Exception exception)
{
JobId = jobId;
Input = input;
Timestamp = DateTime.UtcNow;
Exceptions = new FaultExceptionInfo(exception);
}

public Guid JobId { get; }
public DateTime Timestamp { get; }
public ExceptionInfo Exceptions { get; }
public TInput Input { get; }
}
}
2 changes: 1 addition & 1 deletion src/MassTransit/Turnout/ITurnoutController.cs
@@ -1,4 +1,4 @@
// Copyright 2007-2015 Chris Patterson, Dru Sellers, Travis Smith, et. al.
// Copyright 2007-2016 Chris Patterson, Dru Sellers, Travis Smith, et. al.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
Expand Down
3 changes: 2 additions & 1 deletion src/MassTransit/Turnout/JobRoster.cs
@@ -1,4 +1,4 @@
// Copyright 2007-2015 Chris Patterson, Dru Sellers, Travis Smith, et. al.
// Copyright 2007-2016 Chris Patterson, Dru Sellers, Travis Smith, et. al.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
Expand All @@ -15,6 +15,7 @@ namespace MassTransit.Turnout
using System;
using System.Collections.Concurrent;


/// <summary>
/// Maintains the jobs for a turnout
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/MassTransit/Turnout/TurnoutConfigurationExtensions.cs
Expand Up @@ -56,6 +56,7 @@ public static class TurnoutConfigurationExtensions
var superviseInterval = specification.SuperviseInterval;

turnoutEndpointConfigurator.Consumer(() => new SuperviseJobConsumer(jobRoster, superviseInterval));
turnoutEndpointConfigurator.Consumer(() => new CancelJobConsumer(jobRoster));

var controller = specification.Controller;
IJobFactory<T> jobFactory = specification.JobFactory;
Expand Down

0 comments on commit 9e9b140

Please sign in to comment.