0

Here gem and rails versions:

Gems:

delayed_job (4.1.5)

dalli (2.7.8)

memcached -h | head -1

memcached 1.4.25

Rails

Rails 5.1.5

I run the delayed worker via this file ./bin/delayed_job run which looks like this:

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
require 'delayed/command'
Delayed::Command.new(ARGV).daemonize

When I run the command I get error: error log

The cache store configuration is the following: config.cache_store = :dalli_store, 'localhost:11211'

I connected to memcache server

abv@abv:~/git/csrhub-frontend$ telnet localhost 11211
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
stats
STAT pid 25174
STAT uptime 197
STAT time 1573225519
STAT version 1.4.25 Ubuntu
STAT libevent 2.0.21-stable

ti seems to work.

Then I tried to get data from the Rails console:

irb(main):004:0> Rails.cache.dalli.set('spree/app_configuration/admin_path', '/some/path')
=> 216172782113783808
irb(main):005:0> Rails.cache.dalli.fetch('spree/app_configuration/admin_path')
=> "/some/path"
irb(main):006:0> Rails.cache.dalli.flush
=> [true]
irb(main):007:0> Rails.cache.dalli.fetch('spree/app_configuration/admin_path')
=> nil

It seems to work. I can't find the problem. Any ideas are very much welcome! Thanks.

I printed the Dalli::Client between cache writes:

#<Dalli::Client:0x0000000009104038 @servers=["memcached:11211"], @options={:compress=>nil}, @ring=#<Dalli::Ring:0x000000000a3ab510 @servers=[#<Dalli::Server:0x000000000a3ab7e0 @hostname="memcached", @port=11211, @weight=1, @socket_type=:tcp, @fail_count=0, @down_at=2019-11-08 19:16:10 +0000, @last_down_at=2019-11-08 19:16:10 +0000, @options={:down_retry_delay=>60, :socket_timeout=>0.5, :socket_max_failures=>2, :socket_failure_delay=>0.01, :value_max_bytes=>1048576, :error_when_over_max_size=>false, :compressor=>Dalli::Compressor, :compression_min_size=>1024, :compression_max_size=>false, :serializer=>Marshal, :username=>nil, :password=>nil, :keepalive=>true, :sndbuf=>nil, :rcvbuf=>nil, :compress=>nil}, @sock=nil, @msg="closed stream", @error="IOError", @pid=nil, @inprogress=false, @lock=#<Monitor:0x000000000a3ab3f8 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x000000000a3ab380>>, @version="1.5.16">], @continuum=nil, @failover=true>>
Community
  • 1
  • 1
Hairi
  • 3,318
  • 2
  • 29
  • 68

1 Answers1

0

The problem has been resolved by re-initializing the Dalli cahce within the delayed job itself.

connection = Dalli::Client.new Environment.config('cache_store')['host'].to_s + ':' + Environment.config('cache_store')['port'].to_s

It seems that the environment had not been loaded properly by the worker.

Hairi
  • 3,318
  • 2
  • 29
  • 68