RetailSolutions.Shared.Jobs 1.3.1380

dotnet add package RetailSolutions.Shared.Jobs --version 1.3.1380
                    
NuGet\Install-Package RetailSolutions.Shared.Jobs -Version 1.3.1380
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RetailSolutions.Shared.Jobs" Version="1.3.1380" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RetailSolutions.Shared.Jobs" Version="1.3.1380" />
                    
Directory.Packages.props
<PackageReference Include="RetailSolutions.Shared.Jobs" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RetailSolutions.Shared.Jobs --version 1.3.1380
                    
#r "nuget: RetailSolutions.Shared.Jobs, 1.3.1380"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RetailSolutions.Shared.Jobs@1.3.1380
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RetailSolutions.Shared.Jobs&version=1.3.1380
                    
Install as a Cake Addin
#tool nuget:?package=RetailSolutions.Shared.Jobs&version=1.3.1380
                    
Install as a Cake Tool

RetailSolutions.Shared.Jobs

A .NET library for controlled cronjob execution with distributed locking, database-driven state management, and structured logging.

Overview

RetailSolutions.Shared.Jobs provides a standardized infrastructure for running scheduled jobs in .NET applications. It handles the operational concerns — distributed locks, enable/disable control, execution tracking, and error recording — so each job implementation can focus exclusively on business logic.

Key capabilities:

  • Distributed locking — prevents concurrent execution of the same job across multiple instances using RedLock
  • Database-driven state control — jobs can be enabled or disabled at runtime via a control table
  • Execution tracking — records start time, last successful run, and last error in the database
  • Elasticsearch integration — optional structured log sink via RetailSolutions.Shared.Logs
  • Serilog context — enriches log entries with job name and lock status automatically

Requirements

  • .NET 10.0 or later
  • Oracle database (control table uses Oracle syntax)
  • RetailSolutions.Shared.Cache 1.2.73+ (provides IDistributedLockFactory)
  • RetailSolutions.Shared.Database 1.2.72+
  • RetailSolutions.Shared.Logs 1.2.77+

Installation

dotnet add package RetailSolutions.Shared.Jobs
Install-Package RetailSolutions.Shared.Jobs

Usage

1. Implement IExecutionJob

using RetailSolutions.Shared.Jobs;

public class OrderSyncJob : IExecutionJob
{
    public int IdServico => 42;
    public string UsecaseName => "OrderSyncJob";

    public async Task ExecuteAsync(CancellationToken cancellationToken)
    {
        // Business logic here
    }
}
Member Description
IdServico Unique service ID — must match the IDSERVICO value in INTG_SERV_EXECUCAO
UsecaseName Used as the distributed lock key and as the Usecase log property
ExecuteAsync Job logic; receives a CancellationToken

2. Register and execute

using Microsoft.Extensions.Hosting;
using RetailSolutions.Shared.Jobs;

var builder = Host.CreateApplicationBuilder(args);

builder.Services.AddSingleton<IExecutionJob, OrderSyncJob>();
// Register IDistributedLockFactory via RetailSolutions.Shared.Cache
// Register IElastic via RetailSolutions.Shared.Logs (optional)

var host = builder.Build();
await host.ExecuteJobAsync();

3. Configure options (optional)

await host.ExecuteJobAsync(new JobExecutionOptions
{
    IgnoreJobExecution = false,      // false = enforce DB enable/disable check (default: true)
    ConnectionStringName = "GEMCO",  // Connection string key in appsettings.json (default: "GEMCO")
    SetupElasticsearch = true        // Configure Elasticsearch sink on startup (default: true)
});

When IgnoreJobExecution is false, the job will:

  1. Check INTG_SERV_EXECUCAO.FLATIVO before running
  2. Record start time, last execution time, and any errors in the control table

Database Setup

The library reads from and writes to the INTG_SERV_EXECUCAO Oracle table:

CREATE TABLE INTG_SERV_EXECUCAO (
    IDSERVICO         NUMBER        NOT NULL PRIMARY KEY,
    FLATIVO           VARCHAR2(1)   NOT NULL,   -- 'S' = enabled, 'N' = disabled
    DHRINICIO         DATE,                      -- Start timestamp of current/last run
    DHRULTIMAEXECUCAO DATE,                      -- Timestamp of last successful completion
    LASTUPDATE        DATE,                      -- Timestamp of last status update
    LASTERROR         DATE,                      -- Timestamp of last error
    LASTERRORMSG      VARCHAR2(4000)             -- Last error message
);

Insert a row for each job before deploying:

INSERT INTO INTG_SERV_EXECUCAO (IDSERVICO, FLATIVO) VALUES (42, 'S');

Connection String

{
  "ConnectionStrings": {
    "GEMCO": "Data Source=<host>/<service>;User Id=<user>;Password=<password>;"
  }
}

Distributed Lock Behavior

Locks are acquired with these default parameters:

Parameter Default Description
Expiry 30 s Maximum lock lifetime
Wait 10 s How long to wait before giving up
Retry 1 s Interval between acquisition attempts

If a lock cannot be acquired (another instance is already running), the execution is skipped and a warning is logged. When IgnoreJobExecution is false, the skipped execution is also recorded as an error in the database.

Execution Flow

ExecuteJobAsync()
    │
    ├── [optional] SetupElasticAsync()
    │
    ├── Acquire distributed lock (RedLock)
    │       ├── Lock not acquired → log warning, record error, exit
    │       └── Lock acquired ↓
    │
    ├── [if !IgnoreJobExecution] Check FLATIVO in INTG_SERV_EXECUCAO
    │       └── FLATIVO != 'S' → log warning, exit
    │
    ├── [if !IgnoreJobExecution] SET DHRINICIO = SYSDATE
    │
    ├── ExecuteAsync(cancellationToken)
    │       ├── Exception → log error, SET LASTERROR / LASTERRORMSG, rethrow
    │       └── Success → log information
    │
    └── [if !IgnoreJobExecution] SET LASTUPDATE / DHRULTIMAEXECUCAO = SYSDATE

Logging

All log entries are enriched with a Usecase property set to IExecutionJob.UsecaseName. Entries produced when a lock could not be acquired also include a Service.Lock = true property.

Example log output:

[INF] Usecase=OrderSyncJob  Integração OrderSyncJob concluída
[WRN] Usecase=OrderSyncJob  OrderSyncJob está desabilitado. Verifique a INTG_SERV_EXECUCAO, ignorando a execução...
[WRN] Usecase=OrderSyncJob  Service.Lock=true  OrderSyncJob is locked, ignoring execution...
[ERR] Usecase=OrderSyncJob  <exception message>

API Reference

IExecutionJob

public interface IExecutionJob
{
    int IdServico { get; }
    string UsecaseName { get; }
    Task ExecuteAsync(CancellationToken cancellationToken);
}

JobExecutionOptions

public class JobExecutionOptions
{
    public bool IgnoreJobExecution { get; set; } = true;
    public string ConnectionStringName { get; set; } = "GEMCO";
    public bool SetupElasticsearch { get; set; } = true;
}

JobExecutionExtension.ExecuteJobAsync

public static Task ExecuteJobAsync(this IHost app, JobExecutionOptions options = null)

Resolves IExecutionJob, IDistributedLockFactory, and IConfiguration from the service container and runs the full execution pipeline.

License

Proprietary — Retail Solutions. All rights reserved.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.1380 154 7/6/2026
1.2.110 102 4/30/2026
1.2.79 148 12/13/2025