Permalink
Browse files

First commit.

  • Loading branch information...
giacomelli committed Jun 4, 2014
1 parent 82592b6 commit 0c1a93a124ae654d344aac448bed54141045d44e
Showing with 3,271 additions and 24 deletions.
  1. +20 −20 LICENSE
  2. +159 −4 README.md
  3. +50 −0 src/JobSharp.FunctionalTests/CommandLineTest.cs
  4. BIN src/JobSharp.FunctionalTests/GlobalSuppressions.cs
  5. +49 −0 src/JobSharp.FunctionalTests/JobSharp.FunctionalTests.csproj
  6. +754 −0 src/JobSharp.FunctionalTests/Settings.StyleCop
  7. +15 −0 src/JobSharp.FunctionalTests/Test.cs
  8. +5 −0 src/JobSharp.FunctionalTests/packages.config
  9. +45 −0 src/JobSharp.Sample/App.config
  10. +86 −0 src/JobSharp.Sample/JobSharp.Sample.csproj
  11. +23 −0 src/JobSharp.Sample/Jobs/LongRunningJob.cs
  12. +24 −0 src/JobSharp.Sample/Jobs/ProblematicJob.cs
  13. +23 −0 src/JobSharp.Sample/Jobs/ShortRunningJob.cs
  14. +24 −0 src/JobSharp.Sample/Program.cs
  15. +36 −0 src/JobSharp.Sample/Properties/AssemblyInfo.cs
  16. +5 −0 src/JobSharp.Sample/Settings.StyleCop
  17. +9 −0 src/JobSharp.Sample/packages.config
  18. BIN src/JobSharp.UnitTests/GlobalSuppressions.cs
  19. +96 −0 src/JobSharp.UnitTests/JobInfoTest.cs
  20. +44 −0 src/JobSharp.UnitTests/JobServiceTest.cs
  21. +67 −0 src/JobSharp.UnitTests/JobSharp.UnitTests.csproj
  22. +754 −0 src/JobSharp.UnitTests/Settings.StyleCop
  23. +16 −0 src/JobSharp.UnitTests/Stubs/StubOneJob.cs
  24. +16 −0 src/JobSharp.UnitTests/Stubs/StubTwoJob.cs
  25. +7 −0 src/JobSharp.UnitTests/packages.config
  26. +41 −0 src/JobSharp.sln
  27. +13 −0 src/JobSharp/IJob.cs
  28. +30 −0 src/JobSharp/JobErrorEventArgs.cs
  29. +28 −0 src/JobSharp/JobEventArgs.cs
  30. +127 −0 src/JobSharp/JobInfo.cs
  31. +119 −0 src/JobSharp/JobService.cs
  32. +81 −0 src/JobSharp/JobSharp.csproj
  33. +122 −0 src/JobSharp/LogService.cs
  34. +36 −0 src/JobSharp/Properties/AssemblyInfo.cs
  35. +17 −0 src/JobSharp/Settings.StyleCop
  36. +44 −0 src/JobSharp/WindowsService.cs
  37. +174 −0 src/JobSharp/WindowsServiceFlow.cs
  38. +8 −0 src/JobSharp/packages.config
  39. +104 −0 src/Settings.StyleCop
  40. BIN src/nuget/JobSharp.0.5.0.nupkg
  41. BIN src/nuget/JobSharp.0.5.1.nupkg
  42. BIN src/nuget/JobSharp.0.5.2.nupkg
  43. BIN src/nuget/JobSharp.0.5.3.nupkg
View
40 LICENSE
@@ -1,21 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 Diego Giacomelli
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
The MIT License (MIT)
Copyright (c) 2014 Diego Giacomelli
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
View
163 README.md
@@ -1,4 +1,159 @@
JobSharp
========
An easy-to-use C# jobs runner.
JobSharp
======
An easy-to-use C# jobs runner.
--------
Features
===
- Individual jobs scheduling using Crontab expressions.
- Easy selection of what jobs run in each Windows Service instance.
- Fault Tolerant. An failure in a job will not affect the others jobs running.
- Auto discovering jobs. Just implement IJob interface and your job will be discovered.
- Easy installation and command-line via [Topshelf](https://github.com/phatboyg/Topshelf).
- Run a specific job via -job:<job name> command-line option.
- Fully tested on Windows.
- Working on Visual Studio and Xamarin Studio.
- Unit tests and functional tests.
- 100% code documentation.
- FxCop and StyleCop validated.
- Good (and well used) design patterns.
--------
Setup
===
* In VS|XS add a new "Console Application" project to your solution.
* Install-Package JobSharp
* Create a folder called "Jobs" and create your jobs inside it. To create the job, follow the instructions in ["Creating a job"](#Step1)
* Add an "Application Configuration File" (app.config) to your project.
* Add the key <add key="JobSharp:CronTab" value="1000" /> to the appSettings section.
* Follow the steps described in ["Configuring the job"](#Step2)
* Replace the content of Program.cs file with the code described in step ["Configuring, installing and running your Windows Service"](#Step3)
<a name="Step1">Creating a job</a>
===
```csharp
class MyFirstJob : IJob
{
public void Run()
{
// Put your job's logic or call your domain logic here.
LogService.Write("My first job using JobSharp is running ;)");
}
}
```
<a name="Step2">Configuring the job</a>
===
Add your new job to enabled jobs to the appSettings section (use comma to add more jobs).
```xml
<add key="JobSharp:Jobs" value="MyFirstJob" />
```
Define when the job must run.
```xml
<add key="MyFirstJob:Crontab" value="*/2 * * * *" />
```
This configuration will make the job runs every 2 minutes.
<a name="Step3">Configuring Windows Service</a>
===
Replace the content of the file Program.cs.
```csharp
using JobSharp;
using Skahal.Infrastructure.Logging.Log4net;
using Topshelf;
class Program
{
static void Main(string[] args)
{
WindowsService.Install(
new Log4netLogStrategy ("JobSharpLog"),
c =>
{
c.RunAsLocalSystem();
c.SetDescription("A very simple JobSharp Sample");
c.SetDisplayName("JobSharp Sample");
c.SetServiceName("JobSharpSample");
c.StartAutomatically();
c.EnableShutdown();
});
}
}
```
Configuring the logging
===
The default configuration use Log4net as the log strategy.
To configure log4net take a look on JobSharp.Sample's [App.config](src/JobSharp.Sample/App.Config)
If Log4net does not meet what you need, I doubt ;), you can implement your own ILogStrategy and inject it on WindowsService.Install method call.
<a name="Step4">Installing Windows Service</a>
===
Open a prompt window on directory with your console application .exe file and type: &lt;your console application name&gt;.exe install
<a name="Step4">Running</a>
===
You can run it as a Windows Service or just as a command-line.
More about command-line options in [Topshelf docs](http://docs.topshelf-project.com/en/latest/overview/commandline.html?highlight=command%20line).
Sample
===
There is a sample project called [JobSharp.Sample](src/JobSharp.Sample) in the solution. This sample has the basic bootstrap for a project using JobSharp.
You can [fork](https://github.com/giacomelli/JobSharp/fork) the full source code to see how a JobSharp powered Windows Service looks like.
--------
FAQ
--------
Having troubles?
- Ask on [Stack Overflow](http://stackoverflow.com/search?q=JobSharp)
Roadmap
--------
- Create a configuration section handler to move the configuration from appSettings section to a specific JobSharp section.
--------
How to improve it?
======
- Create a fork of [JobSharp](https://github.com/giacomelli/JobSharp/fork).
- Did you change it? [Submit a pull request](https://github.com/giacomelli/JobSharp/pull/new/master).
License
======
Licensed under the The MIT License (MIT).
In others words, you can use this library for developement any kind of software: open source, commercial, proprietary and alien.
Change Log
======
- 0.5.3 First version.
@@ -0,0 +1,50 @@
using NUnit.Framework;
using System;
using TestSharp;
using System.IO;
using System.Threading;
namespace JobSharp.FunctionalTests
{
[TestFixture ()]
public class CommandLineTest
{
[SetUp]
public void SetUp()
{
ProcessHelper.KillAll ("JobSharp.Sample");
}
[TearDown]
public void TearDown()
{
ProcessHelper.KillAll ("JobSharp.Sample");
}
[Test ()]
public void Run_NoArgs_RunAllJobs ()
{
var sampleProjectFolder = VSProjectHelper.GetProjectFolderPath ("JobSharp.Sample");
var commandLinePath = Path.Combine (sampleProjectFolder, "bin\\Debug\\JobSharp.Sample.exe");
var logsFolder = Path.Combine (sampleProjectFolder, "bin\\Debug\\Logs");
var logFilePath = Path.Combine (sampleProjectFolder, "bin\\Debug\\Logs\\log.txt");
DirectoryHelper.DeleteAllFiles (logsFolder);
ProcessHelper.Run (commandLinePath, "", false);
FileHelper.WaitForFileContentContains (logFilePath, "[END]", 120);
TestSharp.FileAssert.ContainsContent ("[START] 3 jobs", logFilePath);
TestSharp.FileAssert.ContainsContent ("[JOB START] ShortRunningJob", logFilePath);
TestSharp.FileAssert.ContainsContent ("Elapsed time", logFilePath);
TestSharp.FileAssert.ContainsContent ("Next execution", logFilePath);
TestSharp.FileAssert.ContainsContent ("[JOB START] ProblematicJob", logFilePath);
TestSharp.FileAssert.ContainsContent ("[JOB ERROR] Houston, we have a problem!", logFilePath);
TestSharp.FileAssert.ContainsContent ("[JOB START] LongRunningJob", logFilePath);
TestSharp.FileAssert.ContainsContent ("[JOB END]", logFilePath);
TestSharp.FileAssert.ContainsContent("[END]", logFilePath);
TestSharp.FileAssert.IsCountLines(22, logFilePath);
}
}
}
Binary file not shown.
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{1A56F4C2-1982-415E-A392-146B10C10D7D}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>JobSharp.FunctionalTests</RootNamespace>
<AssemblyName>JobSharp.FunctionalTests</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Ionic.Utils.Zip">
<HintPath>..\packages\TestSharp.1.0.2\lib\net40\Ionic.Utils.Zip.dll</HintPath>
</Reference>
<Reference Include="TestSharp">
<HintPath>..\packages\TestSharp.1.0.2\lib\net40\TestSharp.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="CommandLineTest.cs" />
<Compile Include="GlobalSuppressions.cs" />
</ItemGroup>
</Project>
Oops, something went wrong.

0 comments on commit 0c1a93a

Please sign in to comment.