ruby-on-railsmultithreadingdelayed-jobruby-daemons

Persisting thread in delayed_job


So I have a rails app where I want my delayed job process to communicate with an SMPP server. But the problem occurs when I try to send the messages. My thread that I created in an initializer (delayed_job.rb):

if $0.ends_with?('/delayed_job')

 require_relative '../../lib/gateway'
 config = {
  :host => 'SERVER.COM',
  :port => 2345,
  :system_id => 'USERNAME',
  :password => 'PASSWORD',
  :system_type => '', # default given according to SMPP 3.4 Spec
  :interface_version => 52,
  :source_ton  => 0,
  :source_npi => 1,
  :destination_ton => 1,
  :destination_npi => 1,
  :source_address_range => '',
  :destination_address_range => '',
  :enquire_link_delay_secs => 60
}
Thread.new{
    gw = Gateway.new
    gw.start(config)
}
end

But checking my log file for the smpp server, it seems that the thread dies right after it starts. So I guess my question is how to persist the thread while the delayed_job daemon is running?

If I start my rails app in production and I try to send messages individually, it works without a problem, but because delayed_job is a separate process, I can't communicate with the the smpp thread in the rails app from my workers in the delayed_job queues.

Any ideas?


Solution

  • Sorted, decided to separate everything into their own daemons and each would communicate with the database independently as opposed to trying to work with pipes and signals.