1. 程式人生 > >AX2009 批處理作業中使用多線程---獨立任務模式

AX2009 批處理作業中使用多線程---獨立任務模式

data rec light 測試 efi letter mac empty bre

每個工單獨立一個任務。
技術分享圖片


Class

/*
獨立任務模式
*/
class DemoBatchIndividualTasks extends RunBaseBatch
{
     str 20 SalesOrder;
    #define.CurrentVersion(1)
    #localmacro.CurrentList
        SalesOrder
    #endmacro
}
 
public container pack()
{
    return [#CurrentVersion, #CurrentList];
}

public static DemoBatchIndividualTasks construct(str _SalesOrder)
{
    DemoBatchIndividualTasks  c;
    ;
    c = new DemoBatchIndividualTasks();
    c.parmSalesOrder(_SalesOrder);
    return c;
}

public boolean unpack(container packedClass)
{
    Version version = RunBase::getVersion(packedClass);
    switch(version)
    {
        case #CurrentVersion:
            [version,#CurrentList] = packedClass;
            break;
        default:
            return false;
    }
    return true;
}
 
private void parmSalesOrder(str _SalesOrder)
{
    SalesOrder= _SalesOrder;
}

//Single Work item per thread
void run()
{
    SalesTable                          salesTable;
    SalesFormLetter                     formletter;
    Map                                 SalesMap;
     
    select * from salesTable
        where salesTable.salesId == SalesOrder &&
              salesTable.documentStatus == DocumentStatus::none;
 
    if (salesTable)
    {
        formletter = SalesFormLetter::construct(DocumentStatus::Invoice);
        formletter.getLast();
        formletter.resetParmListCommonCS();
        formletter.allowEmptyTable(formletter.initAllowEmptyTable(true));
        SalesMap = new Map(Types::Int64,Types::Record);
        SalesMap.insert(salesTable.recid,salesTable);
//        formletter.parmDataSourceRecordsPacked(SalesMap.pack());
//        formletter.createParmUpdateFromParmUpdateRecord(SalesFormletterParmData::initSalesParmUpdateFormletter(DocumentStatus::Invoice, FormLetter.pack()));
        formletter.showQueryForm(false);
        formletter.initLinesQuery();
        formletter.update(salesTable, systemDateGet(), SalesUpdate::All, AccountOrder::None, false, false);
    }
}

public void new()
{
    super();
}

Job 測試

static void scheduleDemoIndividualTasksJob(Args _args)
{
    BatchHeader                     batchHeader;
    DemoBatchIndividualTasks        demoBatchIndividualTasks;
    BatchInfo                       batchInfo;
    SalesTable                      salesTable;

    SalesId                         _SalesIdFrom,_SalesIdTo;
    ;


    _SalesIdFrom = "SSO000001";
    _SalesIdTo = "SSO001000";
    ttsBegin;
    select count(RecId) from salesTable
        where salesTable.salesId >= _SalesIdFrom &&
            salesTable.salesId <= _SalesIdTo && salesTable.documentStatus == DocumentStatus::none; if (salesTable.recid > 0)
    {
        batchHeader = BatchHeader::construct();
        batchHeader.parmCaption(strFmt(‘Batch job for demoBatchIndividualTasks‘));

        while select * from salesTable
            where salesTable.salesId >= _SalesIdFrom &&
                salesTable.salesId <= _SalesIdTo &&
                salesTable.documentStatus == DocumentStatus::none
        {
            /* Each task is created to process a single work item (in this case a single sales Order)*/
            demoBatchIndividualTasks = DemoBatchIndividualTasks::construct( salesTable.salesid);
            batchInfo = demoBatchIndividualTasks.batchInfo();
            BatchInfo.parmCaption(‘Invoicing : ‘+salesTable.salesid);

            batchInfo.parmGroupId("COUNTING");

            batchHeader.addTask(demoBatchIndividualTasks);
        }
        batchHeader.save();
    }
    ttsCommit;
    info(‘Done‘);
}

/*
獨立任務模式

假設,我們處理10萬條記錄

#創建任務    #批處理線程(在我的測試服務器)    #可並行執行的並行任務
100,000      10                                 10

一旦前10個任務完成,批處理框架將加載後10個任務並執行它們,在這種情況下
,它可以加載10,000或更多次。
*/

  

AX2009 批處理作業中使用多線程---獨立任務模式