通过过程屏幕运行时过程运行良好,但不在自动计划下 [英] Process runs fine while running through process screen but not under automated schedule

查看:58
本文介绍了通过过程屏幕运行时过程运行良好,但不在自动计划下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试安排一个流程。时间表运行时,出现以下错误:

I have a process that I'm trying to schedule. When the schedule runs, I get the following error:

       Message: Error #199: You are not currently logged in.

Date/Time: 09/06/2015 10:20
Platform: 
Browser: 

Source: PX.Data
Target Site: Int32 GetCurrentCompany()
Stack Trace:    at PX.Data.PXDatabaseProviderBase.GetCurrentCompany()
   at PX.Data.PXDatabaseProviderBase.getCompanyID(String tableName, companySetting& setting)
   at PX.Data.PXDatabaseProviderBase.getRestriction(String table, String alias, Boolean mainRestriction, Boolean isRightJoin, Nullable`1 effectiveCid)
   at PX.Data.PXDatabaseProviderBase.alterText(String text, Int32 start, Int32 stop, Boolean isTopLevelQuery)
   at PX.Data.PXDatabaseProviderBase.alterText(String text, Int32 start, Int32 stop, Boolean isTopLevelQuery)
   at PX.Data.PXDatabaseProviderBase.Select(PXGraph graph, BqlCommand command, Int32 topCount, PXView view, PXDataValue[] pars)
   at PX.Data.PXGraph.ProviderSelect(BqlCommand command, Int32 topCount, PXView view, PXDataValue[] pars)
   at PX.Data.PXView.GetResult(Object[] parameters, PXFilterRow[] filters, Boolean reverseOrder, Int32 topCount, PXSearchColumn[] sorts, Boolean& overrideSort, Boolean& extFilter)
   at PX.Data.PXView.Select(Object[] currents, Object[] parameters, Object[] searches, String[] sortcolumns, Boolean[] descendings, PXFilterRow[] filters, Int32& startRow, Int32 maximumRows, Int32& totalRows)
   at PX.Data.PXSelectBase`1.selectBound[Resultset](BqlCommand command, Boolean readOnly, PXGraph graph, Int32 startRow, Int32 totalRows, Object[] currents, Object[] pars)
   at PX.Data.PXSelectBase`1.select[Resultset](BqlCommand command, Boolean readOnly, PXGraph graph, Int32 startRow, Int32 totalRows, Object[] pars)
   at PX.Data.PXSelectReadonly`2.SelectWindowed[Resultset](PXGraph graph, Int32 startRow, Int32 totalRows, Object[] pars)
   at PX.Data.PXSelectReadonly`2.Select[Resultset](PXGraph graph, Object[] pars)
   at Exosoft.MP.MikePero.Graphs.RexApiMaint.GetCustomerByCD(String id)

当我通过我的过程屏幕运行它,但不按照自动计划运行。

The process runs fine when I run it through my process screen but not under an automated schedule.

当我调用下面的内容时发生错误...

Error happens when I call the below...

PXSelectReadonly<PX.Objects.AR.Customer, Where<PX.Objects.AR.Customer.acctCD, Equal<Required<PX.Objects.AR.Customer.acctCD>>>>.Select(this, id);

该图及其调用处理的图是基于我创建的自定义表而自定义的。我已将CompanyID和其他审核字段添加到自定义表中。这就是我的称呼方式。

The graph and the graph it calls to process are custom based on a custom table I created. I have added CompanyID and the other audit fields to the custom table. This is how I am calling it

public class SyncRexApiProcess : PXGraph<SyncRexApiProcess>
{

    public PXCancel<RexApiLogin> Cancel;
    public PXProcessing<RexApiLogin> RexApiLogins;

    public SyncRexApiProcess()
    {
        RexApiLogins.SetProcessCaption("Sync From Rex Api Login");
        RexApiLogins.SetProcessAllCaption("Sync From All Rex Api Logins");
        RexApiLogins.SetProcessDelegate<RexApiMaint>(
            delegate(RexApiMaint graph, RexApiLogin login)
            {
                graph.Clear();
                Func<Task> task = async () =>
                {
                    await graph.SyncAPIDataAsync(login);
                };
                task().Wait();

            });
    }

}


推荐答案

通过使用async / await,您的代码将在另一个线程中运行,不能保证使用会话变量正确初始化该线程。我不相信Acumatica可以保证图形或任何缓存具有任何类型的线程安全性,因此您应该将与之交互的任何代码与异步操作分开。

By using async/await, your code will run in a different thread, which isn't guaranteed to be initialized properly with session variables. I don't believe Acumatica guarantees any sort of thread-safety with the graph or any of the caches, so you should separate any code that interacts with it from your asynchronous operations.

此外,我看不出有使用异步操作的任何理由。在这种情况下,这只会使您的生活更加艰难-只需从主线程运行API同步即可。如果您想一次运行多个操作并等待它们返回,则将这些操作与图形和缓存隔离开来。

Furthermore, I don't see any reason to use an asynchronous operation; it will just make your life harder in this case - just run your API synchronization from the main thread. If you want to run multiple operations at once, and wait for them to return, then isolate these operations from the graph and caches.

这篇关于通过过程屏幕运行时过程运行良好,但不在自动计划下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆