Skip to content
This repository was archived by the owner on May 22, 2021. It is now read-only.
This repository was archived by the owner on May 22, 2021. It is now read-only.

standalone rails in script issues with async-postgres #10

@semdinsp

Description

@semdinsp

I run falcon on heroku and it works perfectly. I use MQTT for communication with some external devices in a low speed internet market.
[Rails 6, postgres 11]

As part of the startup process i have the normal rails webserver (heroku web running falcon) and a script (heroku worker) which access active record (boots rails) for running the MQTT handler. WHEN I install async-postgres the rails webserver continues to work but the script bombs out. The first problem was I had to encapsulate the code in a Async do end statement but after that was done all seems work well locally.

Now it fails in the ActionMailer code on heroku. The difference between local and heroku may be that I use Redis.

I suspect that I need to patch my actionMailer code with an async statement. But any suggestions will be appreciated. I will fiddle with it over the weekend and update this issue if I find a fix.

The basics of the script are:

Async do |task|
begin
  STDOUT.flush 
  mqttmgr = MQTTManager.new
  env, certificatePath, privateKeyPath, rootCAPath=mqttmgr.build_cert_paths(certdir,"fred")
  owner=Setting.first.application_owner if !Setting.first.nil? #FIRST AR/RAILS CALL
  puts "Please set application owner in settings" if Setting.first.nil?
  clientcount=1

  STDOUT.flush

config = {
  :host => "",
  :port =>,
  :env => env,
  :rootca => rootCAPath,
  :certpath => certificatePath,
  :keypath => privateKeyPath,
  :application_owner => owner,
  :keep_alive => 30,
}
STDOUT.flush
client=mqttmgr.start(config)
STDOUT.flush
mqttmgr.read_messages(client,config)

rescue Exception => ex
puts "#{Time.now}: Exception in MQTT Gateway: #{ex} at #{ex.backtrace.join("\n")}"
end

end #ASYNC

stack trace:

2020-01-10T08:52:59.692023+00:00 app[mqtt.1]: /app/vendor/bundle/ruby/2.6.0/gems/async-1.24.0/lib/async/task.rb:183:in current': No async task available! (RuntimeError) 2020-01-10T08:52:59.692052+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/async-postgres-0.1.0/lib/async/postgres/pool.rb:30:in initialize'
2020-01-10T08:52:59.692119+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/async-postgres-0.1.0/lib/async/postgres.rb:29:in new' 2020-01-10T08:52:59.692152+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/async-postgres-0.1.0/lib/async/postgres.rb:29:in connect'
2020-01-10T08:52:59.692184+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/connection_adapters/postgresql_adapter.rb:46:in postgresql_connection' 2020-01-10T08:52:59.692209+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/connection_adapters/abstract/connection_pool.rb:879:in new_connection'
2020-01-10T08:52:59.692256+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/connection_adapters/abstract/connection_pool.rb:923:in checkout_new_connection' 2020-01-10T08:52:59.692305+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/connection_adapters/abstract/connection_pool.rb:902:in try_to_checkout_new_connection'
2020-01-10T08:52:59.692330+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/connection_adapters/abstract/connection_pool.rb:863:in acquire_connection' 2020-01-10T08:52:59.692354+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/connection_adapters/abstract/connection_pool.rb:587:in checkout'
2020-01-10T08:52:59.692378+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/connection_adapters/abstract/connection_pool.rb:431:in connection' 2020-01-10T08:52:59.692401+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/connection_adapters/abstract/connection_pool.rb:1106:in retrieve_connection'
2020-01-10T08:52:59.692440+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/connection_handling.rb:231:in retrieve_connection' 2020-01-10T08:52:59.692487+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/connection_handling.rb:199:in connection'
2020-01-10T08:52:59.692512+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/model_schema.rb:340:in table_exists?' 2020-01-10T08:52:59.692535+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/attribute_methods/primary_key.rb:92:in get_primary_key'
2020-01-10T08:52:59.692558+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/attribute_methods/primary_key.rb:80:in reset_primary_key' 2020-01-10T08:52:59.692582+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/attribute_methods/primary_key.rb:68:in primary_key'
2020-01-10T08:52:59.692620+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/relation/delegation.rb:90:in primary_key' 2020-01-10T08:52:59.692667+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/relation/finder_methods.rb:545:in ordered_relation'
2020-01-10T08:52:59.692692+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/relation/finder_methods.rb:511:in find_nth_with_limit' 2020-01-10T08:52:59.692716+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/relation/finder_methods.rb:504:in find_nth'
2020-01-10T08:52:59.692741+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/relation/finder_methods.rb:120:in first' 2020-01-10T08:52:59.692770+00:00 app[mqtt.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.0.rc2/lib/active_record/querying.rb:21:in first'
2020-01-10T08:52:59.692826+00:00 app[mqtt.1]: from /app/app/mailers/tms_mailer.rb:4:in `class:TmsMailer'

TESTING BOMBS AS WELL
sorry - just saw this error in the rspec.
Failure/Error: ActiveRecord::Migration.maintain_test_schema!
RuntimeError:
No async task available!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions