Now that you’ve created the host application, you can create a job within that application.

A Runly job is a class that extends Runly.Job<TConfig, TItem>. A job has a few basic parts: a config, a list of items to process and a method that performs some work for each item.

Create a Job Class

Create a new file in your project called HelloWorld.cs. In it, paste the following:

using Runly;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Threading.Tasks;

public class HelloWorld : Job<HelloWorldConfig, string>
{
	readonly ILogger<HelloWorld> logger;

	public HelloWorld(HelloWorldConfig config, ILogger<HelloWorld> logger)
		: base(config)
	{
		this.logger = logger;
	}

	public override IAsyncEnumerable<string> GetItemsAsync()
	{
		return Config.Names.ToAsyncEnumerable();
	}

	public override Task<Runly.Result> ProcessAsync(string name)
	{
		logger.LogInformation("Hello, {name}", name);
		return Task.FromResult(Runly.Result.Success());
	}
}

public class HelloWorldConfig : Runly.Config
{
	public string[] Names { get; set; }
		= new string[] { "Rick", "Morty" };
}

This job simply takes a config of names and logs “Hello” to each one of them. The logger in this case is configured with DI via the JobHost. By default, the JobHost configures the logger to just log the console. You can, however, configure the JobHost to log to any logging provider.

The config type HelloWorldConfig inherits from the base Runly.Config and is also injected into the job via the constructor. We setup some default names for the job by assigning a value to the Names property.

Learn more about jobs and how the job methods all work together.

List the Job

Now that you’ve created a job, you can run your application and list all jobs within it:

dotnet run -- list

You should see output similar to the following:

Client Version: v1.0.0

============================================================
MyProject.HelloWorld [MyProject]
============================================================

MyProject.HelloWorldConfig
{
	"names": [
		"Rick",
		"Morty"
	],
	"job": "MyProject.HelloWorld"
}

This outputs the minimal default config for each job found within the application. You can also output the full, verbose config by running:

dotnet run -- list -v

which will give you output similar to the following:

Client Version: v1.0.0

============================================================
MyProject.HelloWorld [MyProject]
============================================================

MyProject.HelloWorldConfig
{
	"names": [
		"Rick",
		"Morty"
	],
	"job": {
		"package": "MyProject",
		"version": "1.0.0",
		"type": "MyProject.HelloWorld"
	},
	"execution": {
		"parallelTaskCount": 1,
		"exceptionRetryCount": 0,
		"unsuccessfulRetryCount": 0,
		"itemFailureCountToStopJob": 1,
		"handleExceptions": true,
		"outputToFile": false,
		"outputFilePath": "",
		"outputToConsole": false,
		"launchDebugger": false
	}
}

Congratulations! You have now built your first job.

Continue to Step 3: Run the Job >>