AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 13.08.2021, 01:32   #1  
Blog bot is offline
Blog bot
Участник
 
25,640 / 848 (80) +++++++
Регистрация: 28.10.2006
axinthefield: Monitoring Long Running Batch Jobs with Power Automate
Источник: https://community.dynamics.com/ax/b/...power-automate
==============

One common question I've been asked is how to monitor for long running batch jobs and send an email alert when it occurs. While there isn’t an out of the box feature for this in the batch framework, you can extend functionality without customization by using business events and Power Automate.

This will be accomplished by configuring a batch job to trigger a Power Automate flow when it is started. The flow will monitor for a specific batch id when a job is executed. If the batch job id matches the job we want to monitor, it will start a delay of 10 minutes. The delay of 10 minutes is the threshold I am defining for when this job is running longer than it should. After the 10 minute delay, the flow will query the application for the status of the job. If it is still executing, an email will be sent.

Please test this thoroughly before adding to a production environment and be mindful of any potential overhead you will be placing on the system. For example, if a recurring job runs every 10 minutes, and the flow queries the status of the job after a 10-minute delay, that will generate around 144 OData queries in a 24-hour period. If you attempt this with a job that runs every minute and set it to email you if it runs longer than a minute, that will generate around 1,440 OData queries in the same period. OData queries are also subject to throttling when under volume. If you monitor multiple batch jobs, the number of queries being performed against your application can get out of hand quickly. Another performance consideration is that business events and batch job processing share the same server threads. For these reasons, please only monitor your most critical jobs and weigh the potential performance impact carefully.

I do not go into much depth on business events in this blog but if you are not familiar with these, you can read more in another blog I wrote here. Now I’ll walk through the steps of enabling the business event on the batch job and creating the flow:



  • In D365FSCM, locate the batch job you want to monitor in System Administration > Inquiries > Batch Jobs. Note the Job Id of the batch job and copy it someplace for later use. I selected the below job which I know will run longer than 10 minutes.

  • Click the Job ID link to view the details of the job.
  • Click the BusinessEvents tab and set Started to Yes. Click OK.

  • Log into the Power Automate portal and select the appropriate environment to create the Power Automate flow in.

  • Click Create on the navigation side bar.
  • Select Automated cloud flow under the Start from blank section.
  • Name your flow something descriptive. For example: D365FSCM – Long Running Batch Job Monitor.
  • Type Fin & Ops in the Choose your flow’s trigger field and select the When a Business Event occurs - Fin & Ops Apps (Dynamics 365) Click Create.

  • You will now have a new flow with a When a Business Event occurs step.
  • Select your F&O environment from the Instance drop down,
    Select Batch for the Category,
    Select Batch job finished for the Business event,Then choose DAT for Legal entity.

  • Click New step and type Parse JSON into the search field for Choose an operation.
  • Click into the Content field and select the body field from Dynamic content.
  • From D365FSCM, navigate to System Administration > Setup > Business events catalog.
  • Under the Business events catalog, highlight the event for Batch job started in the Batch category.
  • Click Download schema. This downloads a text file containing the schema of the JSON payload for the business event that will be used in Power Automate.
  • Copy the contents of the file you downloaded.
  • Return to the Power Automate portal and click the Generate from sample button in the Parse JSON step of your flow.
  • Paste the schema you downloaded and copied previously into the screen that pops up and click Done.

  • Click New step and type Switch into the search box for Choose an operation. Click the Switch control to add.
  • In the On field for the Switch control, select JobId from Dynamic content.


  • Under Case from our Switch step, enter the batch job id for the job to be monitored.

  • Click Add an action and search for Delay under Choose an operation. Click the Delay action to add.
  • Enter 10 into the Count field.
  • Select Minutes for Unit if not already selected. This will cause the flow to wait 10 minutes before proceeding to the next steps of checking if our job is still running.
  • Click Add an action and type Fin & Ops under Choose an operation then click Fin & Ops Apps.
  • Click Get a record.
  • Select the environment that contains your batch job from the Instance drop down,
    Select BatchJobs in the Entity name drop down,
    Enter the batch job id of your batch job under Object id.
  • Click Add an action and type Condition in the search box under Choose an operation. Click Condition to add.
  • Select the Status field from your Dynamic content for the Get a record step.
  • Type Executing in the field after is equal to.

  • Click Add an action in the If yes box.
  • Type Send and email in the search box under Choose an operation. Click Send an email notification (V3) to add to flow. You could also select Send an email (V2) for Office 365 Outlook, but I used the first one.
  • Enter the desired email address in the To field,
    Click into the Subject field and add the Job description field from Dynamic content for Get a record. You can add other text after this, such as ‘ is taking longer to run than usual’. I also added the BatchJobRecId field from the dynamic content at the end.
  • For the Body, I added some text that includes the batch job description and company accounts fields from the Dynamic content. Here’s how it all looks once filled out.

  • Click Save to save your flow.
Now execute your batch job that is defined in the flow. If it runs longer than the delay time of 10 minutes in the flow, you should get an email.



Email Alert:



If you want to monitor multiple jobs, you could add more batch job ids to the switch control in the power automate flow. The power automate flow will evaluate any batch job that is configured for the 'batch job started' business event. Don't let it get out of hand, though!

Thank you for reading and please connect with me on LinkedIn for future blogs and discussion!




Источник: https://community.dynamics.com/ax/b/...power-automate
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
crminthefield: Dynamics 365 and Power Platform Monthly Update-August 2021 Blog bot Dynamics CRM: Blogs 0 12.08.2021 06:20
crminthefield: Dynamics 365 and Power Platform Monthly Update-July 2021 Blog bot Dynamics CRM: Blogs 0 14.07.2021 02:22
crminthefield: Monitoring the Power Platform: Power Automate - Power Automate Analytics Blog bot Dynamics CRM: Blogs 0 14.04.2020 18:11
kurthatlevik: Batch Jobs; Take control of the executions Blog bot DAX Blogs 0 20.01.2020 20:13
patrickmouwen: Dynamics AX Retail: how to automate processes and interfaces in a combined way Blog bot DAX Blogs 0 23.12.2015 23:11

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 04:43.