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:
1 | bin/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:
1 | bin/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:
1 | bin/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
Don’t forget to add –username if you want to see the job in the history of a given user. Example for user ‘admin’: bin/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):
1 | apt-get install cron
|
Then, you can edit your crontab:
1 | crontab -e
|
You can now add a new line at the end of the opened file:
1 | 0 * * * * /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!