Ich habe ein seltsames Problem bei der Verwendung von Sidekiq mit Algoliasearch in meiner Rails-Anwendung.Rails: Worker fehlgeschlagen und Speicherbelegung erhöhen
Immer, wenn ich sidekiq starten, führt es automatisch alle Aktionen I mit Algoliasearch konfiguriert:
# A post model
include AlgoliaSearch
algoliasearch if: :published?, enqueue: :trigger_sidekiq_worker do
attributes :title, :subtitle, :content, :cached_votes_score, :cached_votes_total
# the `searchableAttributes` (formerly known as attributesToIndex) setting defines the attributes
# you want to search in: here `title`, `subtitle` & `description`.
# You need to list them by order of importance. `description` is tagged as
# `unordered` to avoid taking the position of a match into account in that attribute.
searchableAttributes ['title', 'subtitle', 'unordered(content)']
# the `customRanking` setting defines the ranking criteria use to compare two matching
# records in case their text-relevance is equal. It should reflect your record popularity.
customRanking ['desc(cached_votes_score)', 'desc(cached_votes_total)']
end
private
def self.trigger_sidekiq_worker(record, remove)
::Algolia::Blog::PostsWorker.perform_async(record.id, remove)
end
Logs:
$ bundle exec sidekiq
m,
`$b
.ss, $$: .,d$
`$$P,d$P' .,md$P"'
,$$$$$bmmd$$$P^'
.d$$$$$$$$$$P'
$$^' `"^$$$' ____ _ _ _ _
$: ,$$: /___|(_) __| | ___| | _(_) __ _
`b :$$ \___ \| |/ _` |/ _ \ |//|/ _` |
$$: ___) | | (_| | __/ <| | (_| |
$$ |____/|_|\__,_|\___|_|\_\_|\__, |
.d$$ |_|
Signal TTIN not supported
Signal TSTP not supported
Signal USR1 not supported
Signal USR2 not supported
2017-04-25T18:50:30.134Z 5596 TID-c0loo INFO: Running in ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]
2017-04-25T18:50:30.134Z 5596 TID-c0loo INFO: See LICENSE and the LGPL-3.0 for licensing details.
2017-04-25T18:50:30.135Z 5596 TID-c0loo INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org
2017-04-25T18:50:30.136Z 5596 TID-c0loo INFO: Booting Sidekiq 5.0.0 with redis options {:url=>nil}
2017-04-25T18:50:30.138Z 5596 TID-c0loo INFO: Starting processing, hit Ctrl-C to stop
2017-04-25T18:50:30.207Z 5596 TID-1nla70 Algolia::Blog::PostsWorker JID-262b2f8613a197637d05caf3 INFO: start
2017-04-25T18:50:30.539Z 5596 TID-1nla70 Algolia::Blog::PostsWorker JID-262b2f8613a197637d05caf3 INFO: fail: 0.333 sec
2017-04-25T18:50:30.540Z 5596 TID-1nla70 WARN: {"context":"Job raised exception","job":{"class":"Algolia::Blog::PostsWorker","args":[1,false],"retry":true,"queue":"default","jid":"262b2f8613a197637d05caf3","created_at":1493146072.768356,"enqueued_at":1493146072.768356,"error_message":"Couldn't find Blog::Post with 'id'=1","error_class":"ActiveRecord::RecordNotFound","failed_at":1493146230.538659,"retry_count":0},"jobstr":"{\"class\":\"Algolia::Blog::PostsWorker\",\"args\":[1,false],\"retry\":true,\"queue\":\"default\",\"jid\":\"262b2f8613a197637d05caf3\",\"created_at\":1493146072.768356,\"enqueued_at\":1493146072.768356}"}
2017-04-25T18:50:30.541Z 5596 TID-1nla70 WARN: ActiveRecord::RecordNotFound: Couldn't find Blog::Post with 'id'=1
Ich weiß nicht, ob das Verhalten als algolia gedacht scheint Versuchen Sie einfach, einen Datensatz mit der ID von 1 zu indizieren. So weit ich es verstehe, sollte es nur indexieren, nachdem ein Datensatz erstellt, gelöscht oder aktualisiert wurde.
Nachdem der Worker fehlgeschlagen ist, beginnt er neu, so dass ich viel Speicher ansammeln kann. In einigen Fällen erhalte ich auch eine LoadError
, obwohl alle meine Klassen und Namespaces korrekt benannt sind.
Ich weiß nicht, ob das Problem mit Algolia oder Sidekiq ist.
Ich habe festgestellt, dass der [algoliesearch-rails] (https://github.com/algolia/algolasearch-rails) Edelstein (ich benutze es zusammen mit Sidekiq) versucht, Datensätze mit einer ID von '1' zu indizieren wenn ich Sidekiq starte. Ich denke, das verursacht das Problem - ich habe ein Problem auf GitHub [hier] (https://github.com/algolia/algoliasearch-rails/issues/229) geöffnet – jonhue