10. Background Tasks¶
1. How to use¶
As Embedded ERP manages many process and data, some updates are done in background task to avoid server overload and improve navigation. It means that some operation are done in background task and may need a few minutes to be applied.
For example, when you create a purchase order delivery, product reservation are not done immediately.
To process these tasks, Embedded ERP uses the “background task” extension which include the following features :
- Schedule tasks
- Execute tasks in background
- Notify technician when a task fails
- View task history
- Tasks timing statistics
To view the scheduled tasks, select menu ERP > Tools > Background Task
Here are a few task samples :
- Add Order #XXX to selected orders : add a sales order to the selected orders tab in Order Preparation screen
- Create shipment & invoices : Create shipment and invoice for a sales order
- Dispatch order #XXX : when product reservation change for one order, dispatch this order in fullstock / stockless / ignored order
- Notify shipment : send shipment email to customer
- Notify invoice : send invoice email to customer
- Update planning for order #XXX : update sales order planning.
- Update stock for product #XXX : Update product stock, reserved qty, ordered qty
- Update supply needs for product #XXX : Update product supply needs
From a technical standpoint, tasks are executed using server cron every minutes.
It is important that you configure your server to execute magento cron every minutes (at very maximum every 5 minutes).
You can execute task requesting manually your cron using url : http://www.monsite.com/cron.php
On magento 1.8, if you do that, nothing will happen, you have to replace the file /cron.php (at root folder of magento installation) from the one of Magento 1.7 for example)
To display background tasks debug when you launch http://www.monsite.com/cron.php
Please activate System -> configuration -> ERP -> Advanced Stock -> Cron -> Show debug html output
You have to launch it many time manually to catch the debug (the process is longer than the other tries) and when you succeeded You get something like :
Executing task #1 (Dispatch order #28)
—> Executing task #3 (Update product availability status for product #150 (stock information changed))
—> Executing task #4 (Update stocks for product #150 (from order validity change ))
—> Executing task #5 (Update stocks for product #150 (from order is cancel event))
—> Executing task #6 (Update product availability status for product #150 (stock information changed))
—> Executing task #2 (Store real fullstock date for order #28)
—> End executing tasksDelete tasks
ERP > Tools > background task
In this menu you can see if background task have been processed or not
It is very important to have a look at the failed one and to launch them again if they are in “error”.
This screen summarizes every tasks with the following information :
- Id : unique ID for the task
- Created at : date of creation
- Group : when you run manual updates in ERP (for instance, when you refresh all product availability statuses, or distribute orders in order preparation), erp will execute the tasks and display a percentage progress on the screen until it reaches 100%).
This specific kind of execution is called “group task”. If a task belongs to a group, then the group is displayed here
- Description : task description
- Executed at : if the tasks has been executed, the datetime is displayed here
- Result : result of the tasks execution (success or error)
- Result description : display the error message if the task execution failed
- Duration : duration of the task execution (in ms)
- Priority : priority of the task ; to select the next task to execute, ERP will first sort them by priority and then by created time
Available actions :
- Stats : displays a new screen where you can check how many background task are pending, a high number means you server is too slow or configured with a cron timing too low.
- Clear all tasks : delete every tasks (even if they have not been complete). Erp automatically prune executed tasks based on setting in system > configuration > ERP > Background task. DO NOT USE this option unless you know EXACTLY what you are doing
- Clear successful tasks : Delete only executed task (success)
- Run next task : execute the next tasks. This option is useful if your cron experience some lock and you want to check if a specific task raise a fatal error.
- Clear group tasks : Delete only tasks having a group. Tasks group are automatically deleted when the group is Complete. However, if for instance you launch a group tasks (refresh all product availability statuses for instance) and you CLOSE the browser, the remaining tasks will not be executed and it may deal to a lock for the next cron execution (where the progress percentage stuck to 100%).
If you experience such behaviour, delete the group task and try again
Most of the background tasks must have a small execution time (except reindex). If you notice you have very high execution time on some task (more that 5sec) and you cron will be regularly late (many task pending), this require investigation.
System > Configuration > ERP > Background Tasks > General
- Delete failed Tasks ?
- Clear error task (not recommended)
- History Duration
- Number of hours for background task executed to remain.
- Developer Email Address
- If a background task fail, this email will receive an alert.
- Debug Mode
- Useful to display the details of each task execution in cron. (if you encounter an error with “Headers already sent”, please disable this option)
- Store stack trace
- Store the “exception” stack trace in background task if background task fail.