Scheduled Tasks

Estimated time to read: 30 minutes

As a Pricing Manager, I want to recalculate Products based on specified conditions (e.g., new cost, change of Product lifecycle state, new Product, Product with a new color, etc.) so I can ensure up to date prices and reduce price stagnation.

Concept

A business use case can lead to a need to, for example, recalculate a Price List or update some table on a certain repetitive schedule. These are examples of where a scheduled task can be used.

Scheduled tasks are mostly used to "schedule" other jobs which do not have a scheduling capability on their own.

What Is Calculation Flow

The Calculation Flow (CF) is a scheduler where you can schedule tasks - Calculation Flow Logics - to be executed periodically at a certain time.

The Calculation Flow Logic can perform actions which most other logic types cannot - like:

  • Start other jobs, e.g.:

    • Price List calculation

    • LPG recalculation

    • Calculation Field Set

    • Data Load

  • Update domain objects - i.e., it can Add / Update / Delete data in, e.g.:

    • Company Parameters

    • Product Extension

    • Price List

Schema of parts and dependencies

Implementation & Configuration

To set up a scheduled task, you need to:

  1. Implement the Calculation Flow Logic.

  2. Configure a Calculation Flow (in Draft state).

  3. Configure a Flow Item (e.g., set up the scheduling).

  4. Deploy the Calculation Flow.

Calculation Flow Logic

The Calculation Flow Logic is a logic of:

  • type "Pricing Logic"

  • nature "Calculation flow"

Special capabilities of the Calculation Flow Logic:

  • Modification of data - This logic is one of the few which have this right. The functions like api.addOrUpdate() or api.delete() will actually perform the data modification. With other types of logic, those functions do nothing.

  • Execution of other jobs - Besides the usual common binding variables, Calculation Flow also has the actionBuilder variable. This variable is of class CalculationFlowActionBuilder.

There’s also a feature which could be useful when you need to cache/remember some data in between executions, without the need to store it into a table:

  • api.global values persist - Values in api.global Map will survive in between executions of the same Flow Item. So if you put some value into api.global, it will be there even in a week when the same Flow Item is executed again.

Let’s show several examples of how you can start other jobs from Calculation Flow Logic:

Sample of execution of the Price List calculation
actionBuilder.addPricelistAction('Pricelist Name') .setCalculate(true)
Sample of execution of the Calculated Field Set (CFS)
actionBuilder.addCalculatedFieldSetAction('CFS Label') .setCalculate(true)
Sample of execution of the Analytics Data Load
actionBuilder.addDataLoadAction("Customer", "InternalCopy", "DMDS.Customer") .setCalculate(true) actionBuilder.addDataLoadAction('Transaction', 'Refresh', 'DM.Transaction') .setCalculate(true)

Configuration of Calculation Flow

Configuration of Calculation Flow is available under the menu Administration  Configuration  System Configuration  Calculation Flows.

Calculation Flow

The Calculation Flow is the scheduler for a group of potentially unrelated Flow Items. While the Flow Items are not necessarily related, when you deploy the Calculation Flow, you deploy all the Flow Items at the same time.

Draft State

When you create a new Calculation Flow, it will be in the Draft state. Draft state means that the Flow is not active and the schedules will not trigger the Logics.

Deploy the CF

Once you create your Flow Item and assign a Logic to it, you must "Deploy" the CF so that the Flow Items inside become active.The Deploy operation will make a copy of the CF which will be "non-draft", i.e., used by the scheduler.

There is no "un-deploy" button but you can delete the deployed Calculation Flow because you still have the original draft version.

Flow Item

A Flow Item is basically a scheduled task requiring a schedule to be defined and a definition of the associated logic.

Periodic

The task can run only once (non-periodic) or it can be started periodically after a certain number of time units.Do not forget that even the non-periodic Flow item can potentially re-schedule itself in the Logic (i.e., the Logic can change the "Next Run Date" of the Flow Item to some future date-time).

Next Run Date

At what date-time the task will be executed again.If you need to set up a scheduled task, which will be triggered manually (e.g., from a Dashboard using a button), then you can put here a Date far in the future.

Target Date

What date will be set for the Logic as Target Date when it executes.Unless you really need to set up a particular date, keep it empty - then TargetDate will have the value of "today", which is usually what you want.

Testing In Studio

You can run the Calculation Flow logic from Studio using the Test logic button but you should be aware of the following facts:

  • Starting other jobs - You cannot start other jobs from the Calculation Flow Logic in Studio (i.e., in the Test mode). Those functions will not trigger any error, they will return the values as usual but the job will not be triggered. If you need to test the logic inucluding the actual start of other jobs, you must run it as a part of a deployed Flow Item manually in Pricefx UI. Note: This behavior might change after version Bijou (7.0), so the possibility to start jobs in Test mode might be added.

  • Updating domain objects - If you run the logic from Studio and the logic is performing changes in data, then you can allow that behavior by selecting the checkbox "Allow object modification". By default, it is never enabled because data modification can lead to data-loss if you have some bugs in the logic.

Testing In Pricefx UI

To test the logic in Pricefx UI, you need to:

  1. Create a Calculation Flow.

  2. It should contain one Flow Item.

    • For the purpose of testing, you can set up the Next Run Date to some distant future date, so that the Flow Item will not be accidentally triggered until you finish the testing.

  3. Select the Logic on the Flow Item.

  4. Deploy the Calculation Flow.

  5. Use the Run now button to start the scheduled job immediately.

Verification Tools in Calculation Flow

The Calculation Flow job provides information about:

  • Show Trait History (the "magnifying glass" icon) - Shows the history of executions of the Calculation Flow and if it was completed successfully.

  • Show Details (the "info" icon) - If the Calculation Flow Logic is using api.global, then this will show the content of the api.global remembered for this Calculation Flow. Remember - The api.global is persisted between separate executions of the task.

Job & Tasks Tracking

When you start a job from the Calculation Flow Logic (but also when you do it manually - e.g., you start a Data Load), the request will be tracked in the list of Jobs. This list is available in menu Administration  Logs  Jobs&Tasks

So it’s a good place where you can verify that the job (e.g., LPG calculation) was actually triggered and if it already finished.

Also, under the "eye" icon, you can find the Performance Log if you need to check how long the execution of the job took.

Considerations

Possible important considerations which must be borne in mind.

Performance

Scheduled task job is not expected to run too long, there’s a cap for its execution, usually 30 minutes.

Advanced Features

References

Groovy API

Documentation

Knowledge Base

Found an issue in documentation? Write to us.