From 13ba4870c4e471cffa06318f4cd8b353c79e67a3 Mon Sep 17 00:00:00 2001 From: Simon Jenkins Date: Mon, 22 Aug 2022 20:31:19 -0700 Subject: [PATCH 01/11] Connect to Redis --- .env | 1 + .github/workflows/container-deploy.yml | 1 + conf/apache.conf | 1 + cpanfile | 1 + docker-compose.yml | 4 ++++ .../dev-environment-quick-start-guide.md | 1 + lib/ProductOpener/Config2_docker.pm | 6 ++++++ lib/ProductOpener/Config2_sample.pm | 5 +++++ lib/ProductOpener/Products.pm | 15 +++++++++++++++ 9 files changed, 35 insertions(+) diff --git a/.env b/.env index f562afd47d64c..e5352638ac415 100644 --- a/.env +++ b/.env @@ -38,6 +38,7 @@ MONGO_INITDB_ROOT_USERNAME=root MONGO_INITDB_ROOT_PASSWORD=test ROBOTOFF_URL=http://robotoff.openfoodfacts.localhost:5500 # connect to Robotoff running in separate docker-compose deployment EVENTS_URL= +REDIS_URL=searchredis:6379 # Redis runs in a separate docker-compose deployment GOOGLE_CLOUD_VISION_API_KEY= CROWDIN_PROJECT_IDENTIFIER= CROWDIN_PROJECT_KEY= diff --git a/.github/workflows/container-deploy.yml b/.github/workflows/container-deploy.yml index 3dd2e4a54514e..6ddbebd210a07 100644 --- a/.github/workflows/container-deploy.yml +++ b/.github/workflows/container-deploy.yml @@ -113,6 +113,7 @@ jobs: echo "POSTGRES_USER=${{ secrets.POSTGRES_USER }}" >> .env echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" >> .env echo "ROBOTOFF_URL=${{ secrets.ROBOTOFF_URL }}" >> .env + echo "REDIS_URL=${{ secrets.REDIS_URL }}" >> .env echo "GOOGLE_CLOUD_VISION_API_KEY=${{ secrets.GOOGLE_CLOUD_VISION_API_KEY }}" >> .env echo "CROWDIN_PROJECT_IDENTIFIER=${{ secrets.CROWDIN_PROJECT_IDENTIFIER }}" >> .env echo "CROWDIN_PROJECT_KEY=${{ secrets.CROWDIN_PROJECT_KEY }}" >> .env diff --git a/conf/apache.conf b/conf/apache.conf index cc27fee09a049..dfe979a8a2f51 100644 --- a/conf/apache.conf +++ b/conf/apache.conf @@ -17,6 +17,7 @@ PerlPassEnv ROBOTOFF_URL PerlPassEnv EVENTS_URL PerlPassEnv EVENTS_USERNAME PerlPassEnv EVENTS_PASSWORD +PerlPassEnv REDIS_URL PerlPassEnv MONGODB_HOST PerlPassEnv GOOGLE_CLOUD_VISION_API_KEY PerlPassEnv CROWDIN_PROJECT_IDENTIFIER diff --git a/cpanfile b/cpanfile index f04803ec70e98..250a92ea4c438 100644 --- a/cpanfile +++ b/cpanfile @@ -64,6 +64,7 @@ requires 'JSON::Create'; requires 'JSON::Parse'; requires 'Data::DeepAccess'; requires 'XML::XML2JSON'; +requires 'Redis::Client'; # Mojolicious/Minion diff --git a/docker-compose.yml b/docker-compose.yml index cabcf6e59724d..5654ae1aa0611 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,9 +13,13 @@ x-backend-conf: &backend-conf - POSTGRES_USER - POSTGRES_PASSWORD - ROBOTOFF_URL +<<<<<<< HEAD - EVENTS_URL - EVENTS_USERNAME - EVENTS_PASSWORD +======= + - REDIS_URL +>>>>>>> 1e7d429684 (Connect to Redis) - GOOGLE_CLOUD_VISION_API_KEY - CROWDIN_PROJECT_IDENTIFIER - CROWDIN_PROJECT_KEY diff --git a/docs/introduction/dev-environment-quick-start-guide.md b/docs/introduction/dev-environment-quick-start-guide.md index e99d1b9a43f83..657302c738734 100644 --- a/docs/introduction/dev-environment-quick-start-guide.md +++ b/docs/introduction/dev-environment-quick-start-guide.md @@ -77,6 +77,7 @@ The `.env` file contains ProductOpener default settings: | `PRODUCT_OPENER_FLAVOR_SHORT` | can be modified to run different flavors of OpenFoodFacts, amongst `off` (default), `obf`, `oppf`, `opf`.| | `PRODUCERS_PLATFORM` | can be set to `1` to build / run the **producer platform**.| | `ROBOTOFF_URL` | can be set to **connect with a Robotoff instance**.| +| `REDIS_URL` | can be set to **connect with a Redis instance for populating the search index**.| | `GOOGLE_CLOUD_VISION_API_KEY` | can be set to **enable OCR using Google Cloud Vision**.| | `CROWDIN_PROJECT_IDENTIFIER` and `CROWDIN_PROJECT_KEY` | can be set to **run translations**.| | `GEOLITE2_PATH`, `GEOLITE2_ACCOUNT_ID` and `GEOLITE2_LICENSE_KEY` | can be set to **enable Geolite2**.| diff --git a/lib/ProductOpener/Config2_docker.pm b/lib/ProductOpener/Config2_docker.pm index 5b3184923d3f6..e74037ab2e744 100755 --- a/lib/ProductOpener/Config2_docker.pm +++ b/lib/ProductOpener/Config2_docker.pm @@ -49,6 +49,7 @@ BEGIN $events_url $events_username $events_password + $redis_url %server_options ); %EXPORT_TAGS = (all => [@EXPORT_OK]); @@ -96,11 +97,16 @@ my $postgres_url = "postgresql://${postgres_user}:${postgres_password}\@${postgr # enable an in-site robotoff-asker in the product page $robotoff_url = $ENV{ROBOTOFF_URL}; +<<<<<<< HEAD # Set this to your instance of https://github.com/openfoodfacts/openfoodfacts-events # enable creating events for some actions (e.g. when a product is edited) $events_url = $ENV{EVENTS_URL}; $events_username = $ENV{EVENTS_USERNAME}; $events_password = $ENV{EVENTS_PASSWORD}; +======= +# Set this to your instance of the search service to enable writes to it +$redis_url = $ENV{REDIS_URL}; +>>>>>>> 1e7d429684 (Connect to Redis) %server_options = ( private_products => $producers_platform, # 1 to make products visible only to the owner (producer platform) diff --git a/lib/ProductOpener/Config2_sample.pm b/lib/ProductOpener/Config2_sample.pm index abd7fbdc0a0a0..8262bde754929 100644 --- a/lib/ProductOpener/Config2_sample.pm +++ b/lib/ProductOpener/Config2_sample.pm @@ -43,6 +43,7 @@ BEGIN $events_url $events_username $events_password + $redis_url %server_options ); @@ -76,11 +77,15 @@ $crowdin_project_key = ''; # enable an in-site robotoff-asker in the product page $robotoff_url = ''; +<<<<<<< HEAD # Set this to your instance of https://github.com/openfoodfacts/openfoodfacts-events # enable creating events for some actions (e.g. when a product is edited) $events_url = ''; $events_username = ''; $events_password = ''; +======= +$redis_url = ''; +>>>>>>> 1e7d429684 (Connect to Redis) %server_options = ( diff --git a/lib/ProductOpener/Products.pm b/lib/ProductOpener/Products.pm index 36fb99711fc06..aee43a301ea98 100644 --- a/lib/ProductOpener/Products.pm +++ b/lib/ProductOpener/Products.pm @@ -142,6 +142,8 @@ use Data::DeepAccess qw(deep_get); use LWP::UserAgent; use Storable qw(dclone); +use Redis::Client; + use Algorithm::CheckDigits; my $ean_check = CheckDigits('ean'); @@ -1178,6 +1180,9 @@ sub store_product($user_id, $product_ref, $comment) { store("$new_data_root/products/$path/changes.sto", $changes_ref); log_change($product_ref, $change_ref); + # index for search service + index_search_service($product_ref); + $log->debug("store_product - done", { code => $code, product_id => $product_id } ) if $log->is_debug(); return 1; @@ -2414,6 +2419,16 @@ sub index_product($product_ref) return; } +sub index_search_service($product_ref) { + # Now send the barcode to Redis so that it can be indexed + eval { + my $redis_client = Redis::Client->new(host => $ProductOpener::Config2::redis_url); + $redis_client->rpush('search_import_queue', $product_ref->{code}); + }; + if ($@) { + $log->warn("Error connecting to Redis", { error => $@ }) if $log->is_warn(); + } +} sub compute_codes($product_ref) { From 45e24ba82f8489e043113a9fd0c77d3463d6e86b Mon Sep 17 00:00:00 2001 From: Simon Jenkins Date: Mon, 22 Aug 2022 20:55:01 -0700 Subject: [PATCH 02/11] Add return statement --- lib/ProductOpener/Products.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ProductOpener/Products.pm b/lib/ProductOpener/Products.pm index aee43a301ea98..223f05f9ed859 100644 --- a/lib/ProductOpener/Products.pm +++ b/lib/ProductOpener/Products.pm @@ -2428,6 +2428,8 @@ sub index_search_service($product_ref) { if ($@) { $log->warn("Error connecting to Redis", { error => $@ }) if $log->is_warn(); } + + return; } sub compute_codes($product_ref) { From e9a8df006671e6055550ee922244d90bd9bd9bf1 Mon Sep 17 00:00:00 2001 From: Simon Jenkins Date: Wed, 14 Sep 2022 08:00:37 -0700 Subject: [PATCH 03/11] Fix merge --- docker-compose.yml | 3 --- lib/ProductOpener/Config2_docker.pm | 4 +--- lib/ProductOpener/Config2_sample.pm | 4 +--- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 5654ae1aa0611..a40802e0ce481 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,13 +13,10 @@ x-backend-conf: &backend-conf - POSTGRES_USER - POSTGRES_PASSWORD - ROBOTOFF_URL -<<<<<<< HEAD - EVENTS_URL - EVENTS_USERNAME - EVENTS_PASSWORD -======= - REDIS_URL ->>>>>>> 1e7d429684 (Connect to Redis) - GOOGLE_CLOUD_VISION_API_KEY - CROWDIN_PROJECT_IDENTIFIER - CROWDIN_PROJECT_KEY diff --git a/lib/ProductOpener/Config2_docker.pm b/lib/ProductOpener/Config2_docker.pm index e74037ab2e744..0a8c06ddfc68b 100755 --- a/lib/ProductOpener/Config2_docker.pm +++ b/lib/ProductOpener/Config2_docker.pm @@ -97,16 +97,14 @@ my $postgres_url = "postgresql://${postgres_user}:${postgres_password}\@${postgr # enable an in-site robotoff-asker in the product page $robotoff_url = $ENV{ROBOTOFF_URL}; -<<<<<<< HEAD # Set this to your instance of https://github.com/openfoodfacts/openfoodfacts-events # enable creating events for some actions (e.g. when a product is edited) $events_url = $ENV{EVENTS_URL}; $events_username = $ENV{EVENTS_USERNAME}; $events_password = $ENV{EVENTS_PASSWORD}; -======= + # Set this to your instance of the search service to enable writes to it $redis_url = $ENV{REDIS_URL}; ->>>>>>> 1e7d429684 (Connect to Redis) %server_options = ( private_products => $producers_platform, # 1 to make products visible only to the owner (producer platform) diff --git a/lib/ProductOpener/Config2_sample.pm b/lib/ProductOpener/Config2_sample.pm index 8262bde754929..b02c83327be67 100644 --- a/lib/ProductOpener/Config2_sample.pm +++ b/lib/ProductOpener/Config2_sample.pm @@ -77,15 +77,13 @@ $crowdin_project_key = ''; # enable an in-site robotoff-asker in the product page $robotoff_url = ''; -<<<<<<< HEAD # Set this to your instance of https://github.com/openfoodfacts/openfoodfacts-events # enable creating events for some actions (e.g. when a product is edited) $events_url = ''; $events_username = ''; $events_password = ''; -======= + $redis_url = ''; ->>>>>>> 1e7d429684 (Connect to Redis) %server_options = ( From aeda90bafdb8d106058007be7424cf0fa1d66878 Mon Sep 17 00:00:00 2001 From: Simon Jenkins Date: Wed, 14 Sep 2022 21:12:02 -0700 Subject: [PATCH 04/11] Only create Redis connection if URL is set --- lib/ProductOpener/Products.pm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ProductOpener/Products.pm b/lib/ProductOpener/Products.pm index 223f05f9ed859..5876770dadd0b 100644 --- a/lib/ProductOpener/Products.pm +++ b/lib/ProductOpener/Products.pm @@ -2420,6 +2420,11 @@ sub index_product($product_ref) } sub index_search_service($product_ref) { + if ($ProductOpener::Config2::redis_url eq "") + { + $log->warn("Redis URL not provided for search indexing", { error => $@ }) if $log->is_warn(); + return; + } # Now send the barcode to Redis so that it can be indexed eval { my $redis_client = Redis::Client->new(host => $ProductOpener::Config2::redis_url); From ed6e177ef65252b153b30517ce6ecfab1996c890 Mon Sep 17 00:00:00 2001 From: Simon Jenkins Date: Fri, 30 Sep 2022 10:06:31 -0700 Subject: [PATCH 05/11] Move to different file --- lib/ProductOpener/Products.pm | 23 ++----------------- lib/ProductOpener/Redis.pm | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 lib/ProductOpener/Redis.pm diff --git a/lib/ProductOpener/Products.pm b/lib/ProductOpener/Products.pm index 5876770dadd0b..af44ef70d74a8 100644 --- a/lib/ProductOpener/Products.pm +++ b/lib/ProductOpener/Products.pm @@ -133,6 +133,7 @@ use ProductOpener::Data qw/:all/; use ProductOpener::MainCountries qw/:all/; use ProductOpener::Text qw/:all/; use ProductOpener::Display qw/single_param/; +use ProductOpener::Redis qw/:all/; use CGI qw/:cgi :form escapeHTML/; use Encode; @@ -142,8 +143,6 @@ use Data::DeepAccess qw(deep_get); use LWP::UserAgent; use Storable qw(dclone); -use Redis::Client; - use Algorithm::CheckDigits; my $ean_check = CheckDigits('ean'); @@ -1181,7 +1180,7 @@ sub store_product($user_id, $product_ref, $comment) { log_change($product_ref, $change_ref); # index for search service - index_search_service($product_ref); + push_to_search_service($product_ref); $log->debug("store_product - done", { code => $code, product_id => $product_id } ) if $log->is_debug(); @@ -2419,24 +2418,6 @@ sub index_product($product_ref) return; } -sub index_search_service($product_ref) { - if ($ProductOpener::Config2::redis_url eq "") - { - $log->warn("Redis URL not provided for search indexing", { error => $@ }) if $log->is_warn(); - return; - } - # Now send the barcode to Redis so that it can be indexed - eval { - my $redis_client = Redis::Client->new(host => $ProductOpener::Config2::redis_url); - $redis_client->rpush('search_import_queue', $product_ref->{code}); - }; - if ($@) { - $log->warn("Error connecting to Redis", { error => $@ }) if $log->is_warn(); - } - - return; -} - sub compute_codes($product_ref) { my $code = $product_ref->{code}; diff --git a/lib/ProductOpener/Redis.pm b/lib/ProductOpener/Redis.pm new file mode 100644 index 0000000000000..fcd627f2e8be5 --- /dev/null +++ b/lib/ProductOpener/Redis.pm @@ -0,0 +1,43 @@ +use Redis::Client; + +BEGIN +{ + use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS); + @EXPORT_OK = qw( + &push_to_search_service + + ); # symbols to export on request + %EXPORT_TAGS = (all => [@EXPORT_OK]); +} + +use vars @EXPORT_OK ; + +sub init_redis() { + if ($ProductOpener::Config2::redis_url eq "") + { + $log->warn("Redis URL not provided for search indexing", { error => $@ }) if $log->is_warn(); + return undef; + } + # Now send the barcode to Redis so that it can be indexed + eval { + my $redis_client = Redis::Client->new(host => $ProductOpener::Config2::redis_url); + return $redis_client; + + }; + if ($@) { + $log->warn("Error connecting to Redis", { error => $@ }) if $log->is_warn(); + } + return undef; +} + +my $redis_client = init_redis(); + +sub push_to_search_service { + if (defined($redis_client)) { + $redis_client->rpush('search_import_queue', $_[0]->{code}); + } + + return; +} + +1; From db969ea2d7b480754191f51ef326d309f49af316 Mon Sep 17 00:00:00 2001 From: Simon Jenkins Date: Fri, 30 Sep 2022 22:57:42 -0700 Subject: [PATCH 06/11] Fixing error --- lib/ProductOpener/Products.pm | 2 +- lib/ProductOpener/Redis.pm | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/ProductOpener/Products.pm b/lib/ProductOpener/Products.pm index af44ef70d74a8..eada90fa2c6b7 100644 --- a/lib/ProductOpener/Products.pm +++ b/lib/ProductOpener/Products.pm @@ -133,7 +133,7 @@ use ProductOpener::Data qw/:all/; use ProductOpener::MainCountries qw/:all/; use ProductOpener::Text qw/:all/; use ProductOpener::Display qw/single_param/; -use ProductOpener::Redis qw/:all/; +use ProductOpener::Redis qw/push_to_search_service/; use CGI qw/:cgi :form escapeHTML/; use Encode; diff --git a/lib/ProductOpener/Redis.pm b/lib/ProductOpener/Redis.pm index fcd627f2e8be5..e4f9878b228d1 100644 --- a/lib/ProductOpener/Redis.pm +++ b/lib/ProductOpener/Redis.pm @@ -1,4 +1,8 @@ -use Redis::Client; + +package ProductOpener::Redis; + +use ProductOpener::PerlStandards; +use Exporter qw< import >; BEGIN { @@ -12,13 +16,16 @@ BEGIN use vars @EXPORT_OK ; +use Log::Any qw($log); +use ProductOpener::Config2; +use Redis::Client; + sub init_redis() { if ($ProductOpener::Config2::redis_url eq "") { $log->warn("Redis URL not provided for search indexing", { error => $@ }) if $log->is_warn(); return undef; } - # Now send the barcode to Redis so that it can be indexed eval { my $redis_client = Redis::Client->new(host => $ProductOpener::Config2::redis_url); return $redis_client; @@ -32,9 +39,9 @@ sub init_redis() { my $redis_client = init_redis(); -sub push_to_search_service { +sub push_to_search_service($product_ref) { if (defined($redis_client)) { - $redis_client->rpush('search_import_queue', $_[0]->{code}); + $redis_client->rpush('search_import_queue', $product_ref->{code}); } return; From 0595e7a185af7a86a8ccc9d681c4a24675f08362 Mon Sep 17 00:00:00 2001 From: Simon Jenkins Date: Sat, 1 Oct 2022 21:03:14 -0700 Subject: [PATCH 07/11] perl tidy --- lib/ProductOpener/Redis.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ProductOpener/Redis.pm b/lib/ProductOpener/Redis.pm index e4f9878b228d1..56ccd67f82507 100644 --- a/lib/ProductOpener/Redis.pm +++ b/lib/ProductOpener/Redis.pm @@ -2,7 +2,7 @@ package ProductOpener::Redis; use ProductOpener::PerlStandards; -use Exporter qw< import >; +use Exporter qw< import >; BEGIN { From ef153864b882b01f405bf492cf6cd94af07d9f26 Mon Sep 17 00:00:00 2001 From: Simon Jenkins Date: Tue, 4 Oct 2022 20:14:39 -0700 Subject: [PATCH 08/11] Working --- lib/ProductOpener/Redis.pm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/ProductOpener/Redis.pm b/lib/ProductOpener/Redis.pm index 56ccd67f82507..89b4ce70e49b2 100644 --- a/lib/ProductOpener/Redis.pm +++ b/lib/ProductOpener/Redis.pm @@ -21,19 +21,25 @@ use ProductOpener::Config2; use Redis::Client; sub init_redis() { + + $log->debug("init_redis", { redis_url_env => $ENV{REDIS_URL}, redis_url => $ProductOpener::Config2::redis_url } ) if $log->is_debug(); + + $log->warn("REDIS_URL env", {redis_url => $ENV{REDIS_URL} }) if $log->is_warn(); if ($ProductOpener::Config2::redis_url eq "") { $log->warn("Redis URL not provided for search indexing", { error => $@ }) if $log->is_warn(); return undef; } + my $redis_client; eval { - my $redis_client = Redis::Client->new(host => $ProductOpener::Config2::redis_url); - return $redis_client; - + $redis_client = Redis::Client->new(host => $ProductOpener::Config2::redis_url); }; if ($@) { $log->warn("Error connecting to Redis", { error => $@ }) if $log->is_warn(); } + else { + return $redis_client; + } return undef; } @@ -41,7 +47,9 @@ my $redis_client = init_redis(); sub push_to_search_service($product_ref) { if (defined($redis_client)) { - $redis_client->rpush('search_import_queue', $product_ref->{code}); + eval { + $redis_client->rpush('search_import_queue', $product_ref->{code}); + }; } return; From 65d7ba2188c9f67325ad4695023f99b800e08dc0 Mon Sep 17 00:00:00 2001 From: Simon Jenkins Date: Tue, 4 Oct 2022 20:34:33 -0700 Subject: [PATCH 09/11] Perl tidy --- lib/ProductOpener/Redis.pm | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/lib/ProductOpener/Redis.pm b/lib/ProductOpener/Redis.pm index 89b4ce70e49b2..d96a41b08cd9e 100644 --- a/lib/ProductOpener/Redis.pm +++ b/lib/ProductOpener/Redis.pm @@ -4,17 +4,15 @@ package ProductOpener::Redis; use ProductOpener::PerlStandards; use Exporter qw< import >; -BEGIN -{ - use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS); +BEGIN { + use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS); @EXPORT_OK = qw( - &push_to_search_service - - ); # symbols to export on request + &push_to_search_service + ); # symbols to export on request %EXPORT_TAGS = (all => [@EXPORT_OK]); } -use vars @EXPORT_OK ; +use vars @EXPORT_OK; use Log::Any qw($log); use ProductOpener::Config2; @@ -22,20 +20,18 @@ use Redis::Client; sub init_redis() { - $log->debug("init_redis", { redis_url_env => $ENV{REDIS_URL}, redis_url => $ProductOpener::Config2::redis_url } ) if $log->is_debug(); - - $log->warn("REDIS_URL env", {redis_url => $ENV{REDIS_URL} }) if $log->is_warn(); - if ($ProductOpener::Config2::redis_url eq "") - { - $log->warn("Redis URL not provided for search indexing", { error => $@ }) if $log->is_warn(); + $log->debug("init_redis", {redis_url_env => $ENV{REDIS_URL}, redis_url => $ProductOpener::Config2::redis_url}) + if $log->is_debug(); + + $log->warn("REDIS_URL env", {redis_url => $ENV{REDIS_URL}}) if $log->is_warn(); + if ($ProductOpener::Config2::redis_url eq "") { + $log->warn("Redis URL not provided for search indexing", {error => $@}) if $log->is_warn(); return undef; } my $redis_client; - eval { - $redis_client = Redis::Client->new(host => $ProductOpener::Config2::redis_url); - }; + eval {$redis_client = Redis::Client->new(host => $ProductOpener::Config2::redis_url);}; if ($@) { - $log->warn("Error connecting to Redis", { error => $@ }) if $log->is_warn(); + $log->warn("Error connecting to Redis", {error => $@}) if $log->is_warn(); } else { return $redis_client; @@ -45,14 +41,12 @@ sub init_redis() { my $redis_client = init_redis(); -sub push_to_search_service($product_ref) { +sub push_to_search_service ($product_ref) { if (defined($redis_client)) { - eval { - $redis_client->rpush('search_import_queue', $product_ref->{code}); - }; + eval {$redis_client->rpush('search_import_queue', $product_ref->{code});}; } - return; + return; } 1; From 8399735af54dafd50672415843e1a390c767964e Mon Sep 17 00:00:00 2001 From: Simon Jenkins Date: Tue, 4 Oct 2022 20:52:15 -0700 Subject: [PATCH 10/11] Fix perl critic --- lib/ProductOpener/Redis.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ProductOpener/Redis.pm b/lib/ProductOpener/Redis.pm index d96a41b08cd9e..9b2977ebd5ff9 100644 --- a/lib/ProductOpener/Redis.pm +++ b/lib/ProductOpener/Redis.pm @@ -26,7 +26,7 @@ sub init_redis() { $log->warn("REDIS_URL env", {redis_url => $ENV{REDIS_URL}}) if $log->is_warn(); if ($ProductOpener::Config2::redis_url eq "") { $log->warn("Redis URL not provided for search indexing", {error => $@}) if $log->is_warn(); - return undef; + return; } my $redis_client; eval {$redis_client = Redis::Client->new(host => $ProductOpener::Config2::redis_url);}; @@ -36,7 +36,7 @@ sub init_redis() { else { return $redis_client; } - return undef; + return; } my $redis_client = init_redis(); From a2c2881663aafea6d75f2e54f1547a853a59fbaf Mon Sep 17 00:00:00 2001 From: Simon Jenkins Date: Tue, 4 Oct 2022 21:29:18 -0700 Subject: [PATCH 11/11] Add back removed line --- lib/ProductOpener/Products.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ProductOpener/Products.pm b/lib/ProductOpener/Products.pm index eada90fa2c6b7..ad195600e19fd 100644 --- a/lib/ProductOpener/Products.pm +++ b/lib/ProductOpener/Products.pm @@ -2418,6 +2418,7 @@ sub index_product($product_ref) return; } + sub compute_codes($product_ref) { my $code = $product_ref->{code};