Search code examples
batch-processingaxaptadynamics-ax-2012dynamics-ax-2012-r2

Why batch jobs working on one server but not on other one?


I have same code on two servers.

I have job for adding batch job to the queue

static void Job_ScheduleBatch2(Args _args)
{
BatchHeader batHeader;
BatchInfo batInfo;
RunBaseBatch rbbTask;
str sParmCaption = "My Demonstration (b351) 2014-22-09T04:09";
SysRecurrenceData sysRecurrenceData = SysRecurrence::defaultRecurrence();
;
sysRecurrenceData = SysRecurrence::setRecurrenceStartDateTime(sysRecurrenceData, DateTimeUtil::utcNow());
sysRecurrenceData = SysRecurrence::setRecurrenceUnit(sysRecurrenceData,     SysRecurrenceUnit::Minute,1);

rbbTask = new Batch4DemoClass();
batInfo = rbbTask .batchInfo();
batInfo .parmCaption(sParmCaption);
batInfo .parmGroupId(""); // The "Empty batch group".
batHeader = BatchHeader ::construct();
batHeader .addTask(rbbTask);
batHeader.parmRecurrenceData(sysRecurrenceData);
//batHeader.parmAlerts(NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes);
batHeader.addUserAlerts(curUserId(),NoYes::No,NoYes::No,NoYes::No,NoYes::Yes,NoYes::No);
batHeader .save();
info(strFmt("'%1' batch has been scheduled.", sParmCaption));
}

and I have a batch job

class Batch4DemoClass extends RunBaseBatch
{
int methodVariable1;
int metodVariable2;

#define.CurrentVersion(1)
#localmacro.CurrentList
    methodVariable1,
    metodVariable2
endmacro
}

public container pack()
{

 return [#CurrentVersion,#CurrentList];
}


public void run()
{
    // The purpose of your job.
    info(strFmt("epeating batch job Hello from Batch4DemoClass .run at %1"
        ,DateTimeUtil ::toStr(
            DateTimeUtil ::utcNow())
        ));

}

public boolean unpack(container _packedClass)
{
Version version = RunBase::getVersion(_packedClass);

switch (version)
{
    case #CurrentVersion:
        [version,#CurrentList] = _packedClass;
        break;

    default:
        return false;

}
return true;
}

On one server it do runs and in batch history I can see it is saving messages to the batch log and on the other server it does nothing. One server is R2 (running) and R3 (not running).

Both codes are translated to CIL. Both servers are Batch server. I can see the batch jobs in USMF/System administration/Area page inquries. Only difference I can find is that jobs on R2 has filled AOS instance name in genereal and in R3 it is empty. In R2 I can see that info messages in log and batch history but there is nothing in R3.

Any idea how to make batch jobs running?


Solution

  • See how to Configure an AOS instance as a batch server.

    There are 3 preconditions:

    1. Marked as a batch server
    2. Time interval set correctly
    3. Batch group set correctly

    Update:

    Deleting the user of a batch job may make the batch job never complete. Once the execute queue has filled, no further progress will happen. Deleting the offending batch jobs is problematic, as only the owner can do so! Then consider changing BatchJob.aosValidateDelete.