Работник Payola терпит неудачу с 'отношение "payola_subscription" не существует "
ОБНОВЛЕНИЕ Я отправил 30$ вознаграждение для тех, кто исправляет это.
Я использую кнопку "Оформить заказ" и отправляю результат в payola/ подписку /PLAN_CLASS/PLAN_ID.json
Это мое initializers/payola.rb
Payola.configure do |config|
config.background_worker = :active_job
config.secret_key = 'yyy'
config.publishable_key = 'xxx'
config.subscribe('payola.subscription.active') do |sub|
user = User.find_by(email: sub.email)
sub.owner = user
sub.save!
end
config.subscribe 'charge.refunded' do |event|
sale = Payola::Sale.find_by(stripe_id: event.data.object.id)
sale.refund! unless sale.refunded?
end
end
Payola_subscription создается в таблице payola_subscription со статусом ожидания, однако задание, отвечающее за уведомление Stripe, не выполняется со следующей трассировкой:
PG::UndefinedTable: ERROR: relation "payola_subscriptions" does not exist LINE 8: WHERE a.attrelid = '"payola_subscriptions"'::... ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod, (SELECT c.collname FROM pg_collation c, pg_type t WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation), col_description(a.attrelid, a.attnum) AS comment FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"payola_subscriptions"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:88:in `async_exec'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:88:in `block in query'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:566:in `block in log'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:560:in `log'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:87:in `query'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:739:in `column_definitions'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:227:in `columns'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/schema_cache.rb:56:in `columns'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/schema_cache.rb:62:in `columns_hash'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/model_schema.rb:354:in `load_schema!'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/attributes.rb:233:in `load_schema!'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/attribute_decorators.rb:28:in `load_schema!'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/model_schema.rb:349:in `load_schema'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/model_schema.rb:256:in `columns_hash'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/core.rb:192:in `block in find_by'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/core.rb:192:in `each'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/core.rb:192:in `all?'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0.1/lib/active_record/core.rb:192:in `find_by'
/Users/alfredo/.rvm/gems/ruby-2.3.1/bundler/gems/payola-db71531ac30c/app/services/payola/process_subscription.rb:4:in `call'
/Users/alfredo/.rvm/gems/ruby-2.3.1/bundler/gems/payola-db71531ac30c/lib/payola/worker/active_job.rb:17:in `perform'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activejob-5.0.0.1/lib/active_job/execution.rb:34:in `block in perform_now'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:126:in `call'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:455:in `call'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:448:in `block (2 levels) in around'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:286:in `block (2 levels) in halting'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/i18n-0.7.0/lib/i18n.rb:257:in `with_locale'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activejob-5.0.0.1/lib/active_job/translation.rb:7:in `block (2 levels) in <module:Translation>'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:391:in `instance_exec'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:391:in `block in make_lambda'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:285:in `block in halting'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:447:in `block in around'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:455:in `call'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:448:in `block (2 levels) in around'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:286:in `block (2 levels) in halting'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activejob-5.0.0.1/lib/active_job/logging.rb:24:in `block (4 levels) in <module:Logging>'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/notifications.rb:164:in `block in instrument'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/notifications.rb:164:in `instrument'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activejob-5.0.0.1/lib/active_job/logging.rb:23:in `block (3 levels) in <module:Logging>'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activejob-5.0.0.1/lib/active_job/logging.rb:44:in `block in tag_logger'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/tagged_logging.rb:70:in `block in tagged'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/tagged_logging.rb:26:in `tagged'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/tagged_logging.rb:70:in `tagged'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activejob-5.0.0.1/lib/active_job/logging.rb:44:in `tag_logger'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activejob-5.0.0.1/lib/active_job/logging.rb:20:in `block (2 levels) in <module:Logging>'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:391:in `instance_exec'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:391:in `block in make_lambda'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:285:in `block in halting'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:447:in `block in around'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:455:in `call'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:101:in `__run_callbacks__'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:750:in `_run_perform_callbacks'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:90:in `run_callbacks'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activejob-5.0.0.1/lib/active_job/execution.rb:33:in `perform_now'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activejob-5.0.0.1/lib/active_job/execution.rb:22:in `block in execute'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:126:in `call'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:455:in `call'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:448:in `block (2 levels) in around'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:286:in `block (2 levels) in halting'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activejob-5.0.0.1/lib/active_job/railtie.rb:26:in `block (4 levels) in <class:Railtie>'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/execution_wrapper.rb:76:in `wrap'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/reloader.rb:68:in `block in wrap'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/execution_wrapper.rb:76:in `wrap'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/reloader.rb:67:in `wrap'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activejob-5.0.0.1/lib/active_job/railtie.rb:25:in `block (3 levels) in <class:Railtie>'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:391:in `instance_exec'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:391:in `block in make_lambda'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:285:in `block in halting'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:447:in `block in around'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:455:in `call'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:101:in `__run_callbacks__'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:750:in `_run_execute_callbacks'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:90:in `run_callbacks'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activejob-5.0.0.1/lib/active_job/execution.rb:20:in `execute'
/Users/alfredo/.rvm/gems/ruby-2.3.1/gems/activejob-5.0.0.1/lib/active_job/queue_adapters/resque_adapter.rb:44:in `perform'
ОБНОВЛЕНИЕ II
Как и предполагалось, я сейчас вхожу изнутри драгоценного камня. Вот как process_subscription.rb
выглядит сейчас:
module Payola
class ProcessSubscription
def self.call(guid)
p 'All subscriptions:', Payola::Subscription.all
Subscription.find_by(guid: guid).process!
end
end
end
Это вывод:
9:48:07 PM worker.1 | "All subscriptions:"
Итак, в основном нет Subscription
записи на всех.
Интересно, что это то, что я получаю из консоли рельсов:
2.3.1 :002 > Payola::Subscription.all
Payola::Subscription Load (1.2ms) SELECT "payola_subscriptions".* FROM "payola_subscriptions"
=> #<ActiveRecord::Relation [#<Payola::Subscription id: 1, plan_type: "SubscriptionPlan", plan_id: 1, start: nil, status: nil, owner_type: nil, owner_id: nil, stripe_customer_id: nil, cancel_at_period_end: nil, current_period_start: nil, current_period_end: nil, ended_at: nil, trial_start: nil, trial_end: nil, canceled_at: nil, quantity: 1, stripe_id: nil, stripe_token: "tok_19ET9sCkWqwXsgpuB2MAdl1k", card_last4: nil, card_expiration: nil, card_type: nil, error: nil, state: "pending", email: "alfredoreduarte@gmail.com", created_at: "2016-11-11 00:44:45", updated_at: "2016-11-11 00:44:45", currency: "usd", amount: 2900, guid: "d577sp", stripe_status: nil, affiliate_id: nil, coupon: nil, signed_custom_fields: nil, customer_address: nil, business_address: nil, setup_fee: nil, tax_percent: nil>]>
Я начинаю думать, что проблема в том, что работник не имеет ни малейшего представления об этих моделях.
ОБНОВЛЕНИЕ III
Оказывается, что resque не видит ни одной из моих таблиц postgresql, хотя я запускаю это в lib/tasks/resque.rake
:
require 'resque/tasks'
task "resque:setup" => :environment do
ENV['QUEUE'] = '*'
Resque.before_fork = Proc.new do |job|
ActiveRecord::Base.connection.disconnect!
end
Resque.after_fork = Proc.new do |job|
ActiveRecord::Base.establish_connection
end
end
Это не имеет ничего общего с Payola.
1 ответ
Эта часть сообщения об ошибке предполагает, что payola_subscriptions
таблицы нет в базе данных:
...relation "payola_subscriptions" does not exist...
Проверьте bin/rake db:migrate
работает без ошибок и вручную проверьте payola_subscriptions
таблица существует в базе данных с клиентом базы данных.