README.md in lokalise_manager-2.0.0 vs README.md in lokalise_manager-2.1.0

- old
+ new

@@ -63,12 +63,18 @@ ```ruby processes = exporter.export! ``` -`processes` will contain an array of queued background processes as uploading is done in the background on Lokalise. You can perform periodic checks to read the status of the process. Here's a very simple example: +`processes` will contain an array of objects responding to the following methods: +* `success` — usually returns `true` (to learn more, check documentation for the `:raise_on_export_fail` option below) +* `process` — returns an object (an instance of the `Lokalise::Resources::QueuedProcess`) representing a [queued background process](https://lokalise.github.io/ruby-lokalise-api/api/queued-processes) as uploading is done in the background on Lokalise. +* `path` — returns an instance of the `Pathname` class which represent the file being uploaded. + +You can perform periodic checks to read the status of the process. Here's a very simple example: + ```ruby def uploaded?(process) 5.times do # try to check the status 5 times process = process.reload_data # load new data return(true) if process.status == 'finished' # return true is the upload has finished @@ -77,11 +83,12 @@ false # if all 5 checks failed, return false (probably something is wrong) end processes = exporter.export! -uploaded? processes[0] +puts "Checking status for the #{processes[0].path} file" +uploaded? processes[0].process ``` Please don't forget that Lokalise API has rate limiting and you cannot send more than six requests per second. ## Configuration @@ -160,10 +167,32 @@ ```ruby c.skip_file_export = ->(file) { f.split[1].to_s.include?('fr') } ``` -* `max_retries_export` (`integer`) — this option is introduced to properly handle Lokalise API rate limiting. If the HTTP status code 429 (too many requests) has been received, LokaliseRails will apply an exponential backoff mechanism with a very simple formula: `2 ** retries` (initially `retries` is `0`). If the maximum number of retries has been reached, a `Lokalise::Error::TooManyRequests` exception will be raised and the export operation will be halted. By default, LokaliseRails will make up to `5` retries which potentially means `1 + 2 + 4 + 8 + 16 + 32 = 63` seconds of waiting time. If the `max_retries_export` is less than `1`, LokaliseRails will not perform any retries and give up immediately after receiving error 429. +* `max_retries_export` (`integer`) — this option is introduced to properly handle Lokalise API rate limiting. If the HTTP status code 429 (too many requests) has been received, LokaliseRails will apply an exponential backoff mechanism with a very simple formula: `2 ** retries` (initially `retries` is `0`). If the maximum number of retries has been reached, a `Lokalise::Error::TooManyRequests` exception will be raised and the export operation will be halted. By default, LokaliseManager will make up to `5` retries which potentially means `1 + 2 + 4 + 8 + 16 + 32 = 63` seconds of waiting time. If the `max_retries_export` is less than `1`, LokaliseRails will not perform any retries and give up immediately after receiving error 429. +* `raise_on_export_fail` (`boolean`) — default is `true`. When this option is enabled, LokaliseManager will re-raise any exceptions that happened during the file uploading. In other words, if any uploading thread raised an exception, your exporting process will exit with an exception. Suppose, you are uploading 12 translation files; these files will be split in 2 groups with 6 files each, and each group will be uploaded in parallel (using threads). However, suppose some exception happens when uploading the first group. By default this exception will be re-raised for the whole process and the script will never try to upload the second group. If you would like to continue uploading even if an exception happened, set the `raise_on_export_fail` to `false`. In this case the `export!` method will return an array with scheduled processes and with information about processes that were not successfully scheduled. This information is represented as an object with three methods: `path` (contains an instance of the `Pathname` class which says which file could not be uploaded), `error` (the actual exception), and `success` (returns `false`). So, you can use the following snippet to check your processes: + +```ruby +processes = exporter.export! + +processes.each do |proc_data| + if proc_data.success + # Everything is good, the uploading is queued + puts "#{proc_data.path} is sent to Lokalise!" + process = proc_data.process + puts "Current process status is #{process.status}" + else + # Something bad has happened + puts "Could not send #{proc_data.path} to Lokalise" + puts "Error #{proc_data.error.class}: #{proc_data.error.message}" + # Or you could re-raise this exception: + # raise proc_data.error.class + end +end +``` + +* For example, you could collect all the files that were uploaded successfully, re-create the exporter object with the `skip_file_export` option (skipping all files that were successfully imported), and re-run the whole exporting process once again. ### Config to work with formats other than YAML If your translation files are not in YAML format, you will need to adjust the following options: