How to automate imports/exports¶
A common need when it comes to imports/exports is to be able to automate them. As Akeneo PIM provides Symfony commands to manage imports and exports you can easily schedule them.
The batch job command¶
Akeneo PIM provides a simple command to launch jobs:
1bin/console akeneo:batch:publish-job-to-queue [-c|--config CONFIG] [--email EMAIL] [--no-log] [--] <code>
So to run the job csv_product_import you can run:
1bin/console akeneo:batch:publish-job-to-queue csv_product_import --env=prod
Tip
Don’t forget to add –env=prod to avoid memory leaks in dev environment (the default environment for commands)
You can also provide a custom configuration (in JSON format) for the job:
1bin/console akeneo:batch:publish-job-to-queue csv_product_import -c "{\"filePath\": \"/custom/path/to/product.csv\"}" --env=prod
Warning
One daemon or several daemon processes have to be started to execute the jobs. Please follow the documentation Setting up the job queue daemon if it’s not the case.
Tip
Add –username in the job if you want to see it in the User Interface (under the Process tracker page). User permissions are applied on this page: a user can only see the jobs he executed. Adding the username in the job, for instance ‘admin’ will allow the user ‘admin’ to see the cron tasks executed with its username. Below an example of a command using the username ‘admin’:
1bin/console akeneo:batch:publish-job-to-queue csv_product_import --env=prod --username admin
Scheduling the jobs¶
To run a command periodically, you can use a cron:
First, you need to install it (example in debian/ubuntu based distributions):
1apt-get install cron
Then, you can edit your crontab:
1crontab -e
You can now add a new line at the end of the opened file:
10 * * * * /home/akeneo/pim/bin/console akeneo:batch:publish-job-to-queue csv_product_import -c "{\"filePath\": \"/custom/path/to/product.csv\"}" --env=prod > /tmp/import.log
With this cron configuration a product import will be pushed into the job queue every hour with the file /custom/path/to/product.csv. It will be processed as soon as a daemon process is pending for a new job to execute. Therefore, the execution of your job could be delayed.
Warning
One daemon or several daemon processes have to be started to execute the jobs. Please follow the documentation Setting up the job queue daemon if it’s not the case.
Found a typo or a hole in the documentation and feel like contributing?
Join us on Github!