Job Queue Scheduler

Scheduler and error handling for the standard Business Central Job Queue.

Helps handle and schedule tasks via job queue. One master job queue entry is used to schedule, monitor and restart recurring job queue entries.

Setup

If the Job Queue Scheduler Status is not faviorable and running the user can then click the status message or Restart Job Queue to create or update the management job queue entry.

From the Job Queue Scheduler Setup the user can lookup the standard job queue entries.

The management job queue entry is by default running every 5 minutes. This can be changed from the standard job queue entry card.

Restarting the management job queue from the Job Queue Scheduler Setup card will reset these recurrence settings. The management job queue will be started using the configured Job Queue Category Code.

The job queue category is created by the Job Queue Scheduler by default. If detailed logging is required for the scheduler entries then enable the job queue activity log. If enabled then a log entry will be created every time the management codeunit checks the job queue entry status. If not enabled the management codeunit will only log when a job queue entry is restarted.

Features

Scheduler will create a Job Queue Entry for all unblocked entries. The Scheduled column in the Scheduler Entries will show if the job queue entry is scheduler in the standard job queue entry. When blocking a scheduler entry the user will be asked about deleting the job queue entry. Updating column values in the scheduler entry will result in an update to the scheduled job queue entry.

The run once action has identical functionality as the same action on the standard job queue entry. The selected scheduler entry will be executed in the foreground. This is useful for debugging.

Reschedule action will delete the scheduled job queue entry and when the management job queue entry executes next, a new job queue entry will be scheduled.

Schedule now will also delete the scheduled job queue entry, but the new job queue entry will also be created. By doing this, the new job queue entry will be executed in your user context, not the user context that is running the management codeunit.

Activity log will lookup the activity log. This may be empty, based on the log settings in the scheduler setup.

The job queue entry action will open the job queue entry card for the scheduled job queue entry. Here the recurrence can be better configured.

The drill down action will execute an event described below. The app that created the scueduler entry should have a subscriber to this event to open the related entry in that app.

The notification type is extensible with built in values as None and EMail.

Developer Reference

Notification Interface

The interface has the following procedures.

procedure SendExecutionCompletedNotification(JobQueueSchedulerEntry: Record O4NJobQueueSchedulerEntry; JobQueueEntry: Record "Job Queue Entry");

Executed after every execution of a job queue entry that is registered with the job queue schedulerer.

procedure SendRestartNotification(JobQueueSchedulerEntry: Record O4NJobQueueSchedulerEntry; JobQueueEntry: Record "Job Queue Entry");

Executed if the schedulerer needs to restart a job queue entry.

procedure ValidateNotificationReceipient(JobQueueSchedulerEntry: Record O4NJobQueueSchedulerEntry);

Executed when the user enters a value in the notification .

procedure SendHeartbeatNotification(JobQueueSchedulerEntry: Record O4NJobQueueSchedulerEntry);

Executed when the management codeunit checks the status of a scheduler entry.

procedure IsNotificationReceipientMandatory() IsMandatory: boolean

Used in the user interface to show a mandatory star if value is mandatory.

Built in enum types are; None and EMail.

enum 70600 O4NJobQSchdlrNotificationType implements O4NJobQSchdlrNotification
{
    Extensible = true;

    value(0; None)
    {
        Caption = 'None';
        Implementation = O4NJobQSchdlrNotification = O4NNoneSchedulerNotification;
    }
    value(1; EMail)
    {
        Caption = 'EMail';
        Implementation = O4NJobQSchdlrNotification = O4NEmailSchedulerNotification;
    }
}

For none notification type an empty notification receipient will be enforced and no action will be executed. A custom app has events to subscribe to to extend this functionality.

For email notification type a notification receipient should be a semicolon separated list of email addresses. Email notifications are only sent when a job queue entry is restarted. A custom app has events to subscribe to to extend this functionality.

Registration Event

[EventSubscriber(ObjectType::Table, Database::O4NJobQueueSchedulerEntry, 'OnRegisterJobQueueCodeunits', '', false, false)]
local procedure OnRegisterJobQueueCodeunits(Rec: Record O4NJobQueueSchedulerEntry);
begin
end;

Called when the app in installed and upgraded and also when the Job Queue Scheduler Setup page is opened. Using this event, another app can register a job to the scheduler.

Example Code
[EventSubscriber(ObjectType::Table, Database::O4NJobQueueSchedulerEntry, 'OnRegisterJobQueueCodeunits', '', false, false)]
local procedure OnRegisterJobQueueCodeunits(Rec: Record O4NJobQueueSchedulerEntry);
begin
    RegisterJobQueue(Rec);
end;

internal procedure RegisterJobQueue(var Rec: Record O4NJobQueueSchedulerEntry)
begin
    if Rec.Get(GetJobQueueGuid()) then exit;

    Rec.Init();
    Rec.ID := GetJobQueueGuid();
    Rec.Blocked := true;
    Rec.Validate("Object Type to Run", Rec."Object Type to Run"::Codeunit);
    Rec.Validate("Object ID to Run", Codeunit::"OSR Currency Exch. Rate Import");
    Rec.Description := JobQueueDescriptionTok;
    Rec."Job Queue Category Code" := FindOrCreateJobQueueCategoryCode();
    Rec.Validate("No. of Minutes between Runs", 1440);
    Rec.Insert();
end;

local procedure GetJobQueueGuid() JobQueueGuid: Guid
begin
    JobQueueGuid := '233b7372-fc52-40c0-a810-9779f11e423f';
end;

local procedure FindOrCreateJobQueueCategoryCode() CategoryCode: Code[10]
var
    JobQueueCategory: Record "Job Queue Category";
    ConcurCategoryCodeTok: Label 'CURRIMP', MaxLength = 10;
    ConcurCategoryDescriptionTok: Label 'Currency Import Process', MaxLength = 30;
begin
    CategoryCode := ConcurCategoryCodeTok;
    if JobQueueCategory.Get(CategoryCode) then exit;
    JobQueueCategory.Init();
    JobQueueCategory.Code := CategoryCode;
    JobQueueCategory.Description := ConcurCategoryDescriptionTok;
    JobQueueCategory.Insert();
end;

Drilldown Event

[EventSubscriber(ObjectType::Table, Database::O4NJobQueueSchedulerEntry, 'OnDrillDownToRelatedEntry', '', false, false)]
local procedure OnDrillDownToRelatedEntry(Rec: Record O4NJobQueueSchedulerEntry);
begin
end;

Called when the user pressed the Drill Down action on the scheduler entry.

Example Code
[EventSubscriber(ObjectType::Table, Database::O4NJobQueueSchedulerEntry, 'OnDrillDownToRelatedEntry', '', false, false)]
local procedure OnDrillDownToRelatedEntry(Rec: Record O4NJobQueueSchedulerEntry);
begin
    if Rec.ID <> GetJobQueueGuid() then exit;
    Page.Run(Page::"OSR Currency Exch. Rate Setup");
end;
Linking a record
Rec."Record ID to Process" := "OSR Currency Exch. Rate Setup".RecordId;
Rec."Related Record System Id" := "OSR Currency Exch. Rate Setup".SystemId;

“Record ID to Process” will be copied to the “Job Queue Entry”.”Record ID to Process”.
These two fields can be used to specify a record both for the job queue execution and also for the drilldown functionality.

API References

Replace http://bcserver:7048/BC with the endpoint address to your environment.

Get Companies

    GET http://bcserver:7048/BC/api/v2.0/companies 

Retrieve a list of companies.

Get Metadata information for Job Queue Scheduler API

    GET http://bcserver:7048/BC/api/kappi/jobQueueScheduler/v1.0/$metadata#companies(<companyId>)  

Retrieve metadata information for the Job Queue Scheduler API.

Get Job Queue Scheduler Status

    GET http://bcserver:7048/BC/api/kappi/jobQueueScheduler/v1.0/companies(<companyId>)/status

Retrieve the status of the Job Queue Scheduler.

Restart the Job Queue Scheduler Job Queue if needed

    POST http://bcserver:7048/BC/api/kappi/jobQueueScheduler/v1.0/companies(<companyId>)/status(<setupRecordSystemId>)/Microsoft.NAV.restartIfNeeded

Restart the Job Queue Scheduler's job queue if needed.

Restart the Job Queue Scheduler Job Queue

    POST http://bcserver:7048/BC/api/kappi/jobQueueScheduler/v1.0/companies(<companyId>)/status(<setupRecordSystemId>)/Microsoft.NAV.restart

Restart the Job Queue Scheduler's job queue.

Get, Create, Update Job Queue Schedules

    GET http://bcserver:7048/BC/api/kappi/jobQueueScheduler/v1.0/companies(<companyId>)/scheduledEntries

Retrieve the job queue schedules.

Get, Update Single Job Queue Scheduler Entry

    GET http://bcserver:7048/BC/api/kappi/jobQueueScheduler/v1.0/companies(<companyId>)/scheduledEntries(<jobQueueId>)

Retrieve a single job queue scheduler entry.

Schedule an update to the Job Queue Entry by the management Job Queue

    POST http://bcserver:7048/BC/api/kappi/jobQueueScheduler/v1.0/companies(<companyId>)/scheduledEntries(<jobQueueId>)/Microsoft.NAV.scheduleJobQueueEntryUpdate

Schedule an update to the job queue entry by the management job queue.

Update the Job Queue Entry as the login user

    POST http://bcserver:7048/BC/api/kappi/jobQueueScheduler/v1.0/companies(<companyId>)/scheduledEntries(<jobQueueId>)/Microsoft.NAV.updateJobQueueEntry

Update the job queue entry as the login user.

Get, Create, Update Job Queue Entries

    GET http://bcserver:7048/BC/api/kappi/jobQueueScheduler/v1.0/companies(<companyId>)/queueEntries

Retrieve the job queue entries.

Get, Update Single Job Queue Entry

    GET http://bcserver:7048/BC/api/kappi/jobQueueScheduler/v1.0/companies(<companyId>)/queueEntries(<jobQueueId>)

Retrieve a single job queue entry.

Insert or update Job Queue Scheduler Entry from the Job Queue Entry

    POST http://bcserver:7048/BC/api/kappi/jobQueueScheduler/v1.0/companies(<companyId>)/queueEntries(<jobQueueId>)/Microsoft.NAV.addToJobQueueScheduler

Insert or update a job queue scheduler entry from the job queue entry.

Get Job Queue Log Entries

    GET http://bcserver:7048/BC/api/kappi/jobQueueScheduler/v1.0/companies(<companyId>)/queueLogEntries

Retrieve the job queue log entries.

Get Job Queue Categories

    GET http://bcserver:7048/BC/api/kappi/jobQueueScheduler/v1.0/companies(<companyId>)/queueCategories

Retrieve the job queue categories.  Use PUT to update and POST to create a new category.