Ruby on rails Rails:工作进程失败并增加内存使用

Ruby on rails Rails:工作进程失败并增加内存使用,ruby-on-rails,backgroundworker,sidekiq,algolia,ruby-on-rails-5.1,Ruby On Rails,Backgroundworker,Sidekiq,Algolia,Ruby On Rails 5.1,我在Rails应用程序中使用with时遇到了一个奇怪的问题 每当我启动sidekiq时,它都会自动执行我使用Algoliasearch配置的所有操作: # A post model include AlgoliaSearch algoliasearch if: :published?, enqueue: :trigger_sidekiq_worker do attributes :title, :subtitle, :content, :cached_votes_score, :cac

我在Rails应用程序中使用with时遇到了一个奇怪的问题

每当我启动sidekiq时,它都会自动执行我使用Algoliasearch配置的所有操作:

# 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
日志:

$bundle exec sidekiq
M
`b美元
.ss,$$:,d$
`$$P,d$P',md$P“
,$$$$$bmmd$$$$P^'
.d$$$$$P'
$$^' `"^$$$'       ____  _     _      _    _
$:     ,$$:       / ___|(_) __| | ___| | _(_) __ _
`b:$$\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\|
$$:uuuuu| | | | | uu|/无}
2017-04-25T18:50:30.138Z 5596 TID-c0loo信息:开始处理,点击Ctrl-C停止
2017-04-25T18:50:30.207Z 5596 TID-1nla70 Algolia::Blog::PostsWorker JID-262b2f8613a197637d05caf3信息:开始
2017-04-25T18:50:30.539Z 5596 TID-1nla70 Algolia::Blog::PostsWorker JID-262b2f8613a197637d05caf3信息:失败:0.333秒
2017-04-25T18:50:30.540Z 5596 TID-1nla70警告:{“上下文”:“作业引发的异常”,“作业”:{“类”:“Algolia::Blog::PostsWorker”,“args”:[1,false],“retry”:true,“队列”:“default”,“jid”:“262b2f8613a197637d05caf3”,“创建时间”:1493146072.768356,“排队时间”:1493146072.768356,“错误消息”找不到“id”=1的博客::Post”,“错误类别”:“ActiveRecord::RecordNotFound”,“失败时间”:1493146230.538659,“重试计数”:0},“jobstr”:“{”class\:“Algolia::Blog::PostsWorker\”,“args\”:[1,false],“重试”:true,“队列\”:“default\”,“jid\:“262b2f8613a197637d05caf3\”,“created\”:1493146072.768356,““排队时间”:1493146072.8356}
2017-04-25T18:50:30.541Z 5596 TID-1nla70警告:ActiveRecord::RecordNotFound:找不到“id”为1的博客::帖子
我不知道这种行为是否是故意的,因为algolia似乎只是尝试为id为1的记录编制索引。据我所知,它应该只在创建、删除或更新记录后编制索引。

在worker失败后,它会重新启动,因此我积累了大量内存。在某些情况下,即使我所有的类和名称空间都正确命名,我也会收到
LoadError


我不知道问题出在Algolia还是Sidekiq上。

我猜它的队列中有一个任务来索引一个不再存在的对象

队列应该正确地处理它,我不知道为什么不能

你能试着清理一下你的Sidekiq队列吗? 要清除所有队列,请运行:

Sidekiq::Queue.all.each &:clear

在控制台中,然后重试。

我猜它的队列中有一个作业,用于索引不再存在的对象

队列应该正确地处理它,我不知道为什么不能

你能试着清理一下你的Sidekiq队列吗? 要清除所有队列,请运行:

Sidekiq::Queue.all.each &:clear
在控制台中,然后重试。

我注意到,每当我启动Sidekiq时,gem(我与Sidekiq一起使用)都会尝试索引id为
1
的记录。我认为这是问题的原因-我在GitHub上打开了一个问题,我注意到gem(我与Sidekiq一起使用)每当我启动Sidekiq时,都会尝试索引id为
1
的记录。我认为这是问题的原因-我在GitHub上打开了一个问题