WHY SCHEDULAR IN LIFERAY 7.3?

Here are some key aspects of automation in Liferay 7.3 using the Dispatcher:

  • Event-driven automation: Liferay Dispatcher allows you to define actions that are triggered by specific events within the portal. These events can be system events, such as user creation or document modification, or custom events that you define within your application. When an event occurs, the Dispatcher can execute predefined actions or workflows automatically.
  • Rules and conditions: The Dispatcher provides a rule-based approach to automation. You can define rules that specify the conditions under which an action should be triggered. For example, you can define a rule that states "When a new document is uploaded and its category is 'Important,' send an email notification to specific users." The Dispatcher evaluates the rules against the events and executes the corresponding actions when the conditions are met.
  • Predefined actions: Liferay 7.3 comes with a set of built-in actions that can be executed by the Dispatcher. These actions include sending email notifications, creating tasks, updating content, executing scripts, invoking web services, and more. You can combine multiple actions within a rule to achieve complex automation scenarios.
  • Custom actions: In addition to the predefined actions, you can create custom actions to extend the capabilities of the Dispatcher. Custom actions allow you to integrate with external systems, execute custom business logic, or perform any other custom operations required for your automation needs.
  • User-friendly interface: Liferay 7.3 provides a user-friendly interface within the administration console for configuring and

managing the Dispatcher. You can define rules, set up actions, manage triggers and events.

Benefits of Automation

  • Efficient Task Execution: You can schedule and execute tasks asynchronously, enabling your application to handle time-consuming operations without blocking the user interface. By leveraging automation, you can offload heavy tasks to background processes, ensuring a smooth user experience.
  • Scalability: You can scale your application by processing tasks in parallel. You can distribute workloads across multiple instances or nodes, enhancing your application's performance and accommodating increased user demand.
  • Workflow Automation: Automate complex business workflow. For example, you can automate content publishing processes, user onboarding tasks, or notifications based on specific events. This improves efficiency and reduces manual effort in managing various aspects of your application.
  • Time Savings and Increase Productivity: Save time and reduces repetitive manual work. This allows developers and administrators to focus on more strategic and value-added activities, ultimately increasing productivity and freeing up resources for other tasks.

doExecute (Automation in Liferay)

To use the `doExecute` method in Liferay's Dispatcher interface, you need to follow these steps:

1.Create a class that extends the ` BaseDispatchTaskExecutor `. This class defines the `doExecute` method that you will override to perform your automation tasks.

public class MyTaskExecutor extends BaseDispatchTaskExecutor {

/**

   * overiding the doExecute method

   */

  @Override

  public void doExecute(

  DispatchTrigger dispatchTrigger,

  DispatchTaskExecutorOutput dispatchTaskExecutorOutput)

  throws IOException, PortalException {

//implement you task execution logic here

//this method will be called when the scheduled trigger is activated

//you can perform your desired tasks or invoke other methods or services

 

2. Configure the MyTaskExecutor properties: In the component annotation of the MyTaskExecutor class, you can specify the properties for scheduling the task.

 

@Component(

  immediate = true,

  property = {

  "dispatch.task.executor.name=“+”TaskExecutor”,

  "dispatch.task.executor.type="+” TaskExecutor “

  },

  service = DispatchTaskExecutor.class

  )

 

USE JOB SCHEDULAR OR MESSAGE LISTENER

Job Scheduler tasks are more flexible than jobs scheduled using MessageListener, because you can make changes to the tasks at runtime through the Job Scheduler UI. Changes to MessageListener jobs must be coded, compiled, and redeployed. The Job Scheduler UI also provides a more complete overview of each Job Scheduler task’s execution properties (e.g., Cron expression, start/end date, cluster mode) and execution history. This information is not provided in the UI for MessageListener jobs.

Configure Scheduler

•  Log in to your Liferay portal as an Administrator
•  In the Control Panel, you will find the “Dispatch” option under the “Configuration” section.
 

 

Within the Dispatch interface, you'll have various options and functionalities to manage and execute tasks.

•Task List: Displays a list of tasks that have been scheduled or executed like below.
 

 
•  Schedule New Task: Allows you to schedule a new task by clicking on “+” icon and  specifying the task's details, such as task name, description, class name, and scheduling options (e.g., cron expression) like below.
 

 
 
•  Execute Now: Provides the ability to manually trigger the immediate execution of a specific task.
•  View Task Details: Allows you to view the details of a specific task, including its execution status, schedule, and history.
•  Edit Task: Enables you to modify the details of an existing task, such as the scheduling options or class name.
•  Delete Task: Lets you remove a scheduled task from the system.