From a692318382ae9eefe6e64bb8d6362cf8812135fd Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 30 Nov 2016 15:24:57 +0100 Subject: [PATCH] Track successful PuSH deliveries --- app/views/admin/pubsubhubbub/index.html.haml | 6 ++++++ app/workers/pubsubhubbub/delivery_worker.rb | 2 ++ ..._last_successful_delivery_at_to_subscriptions.rb | 5 +++++ db/schema.rb | 13 +++++++------ 4 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20161130142058_add_last_successful_delivery_at_to_subscriptions.rb diff --git a/app/views/admin/pubsubhubbub/index.html.haml b/app/views/admin/pubsubhubbub/index.html.haml index bb897eb895..ad8cf51983 100644 --- a/app/views/admin/pubsubhubbub/index.html.haml +++ b/app/views/admin/pubsubhubbub/index.html.haml @@ -5,6 +5,7 @@ %th Callback URL %th Confirmed %th Expires in + %th Last delivery %tbody - @subscriptions.each do |subscription| %tr @@ -16,5 +17,10 @@ - if subscription.confirmed? %i.fa.fa-check %td= distance_of_time_in_words(Time.now, subscription.expires_at) + %td + - if subscription.last_successful_delivery_at.nil? + %i.fa.fa-times + - else + = l subscription.last_successful_delivery_at = will_paginate @subscriptions, pagination_options diff --git a/app/workers/pubsubhubbub/delivery_worker.rb b/app/workers/pubsubhubbub/delivery_worker.rb index 6d526c2b12..20c72ce243 100644 --- a/app/workers/pubsubhubbub/delivery_worker.rb +++ b/app/workers/pubsubhubbub/delivery_worker.rb @@ -19,6 +19,8 @@ class Pubsubhubbub::DeliveryWorker .post(subscription.callback_url, body: payload) raise "Delivery failed for #{subscription.callback_url}: HTTP #{response.code}" unless response.code > 199 && response.code < 300 + + subscription.touch(:last_successful_delivery_at) end private diff --git a/db/migrate/20161130142058_add_last_successful_delivery_at_to_subscriptions.rb b/db/migrate/20161130142058_add_last_successful_delivery_at_to_subscriptions.rb new file mode 100644 index 0000000000..614155b910 --- /dev/null +++ b/db/migrate/20161130142058_add_last_successful_delivery_at_to_subscriptions.rb @@ -0,0 +1,5 @@ +class AddLastSuccessfulDeliveryAtToSubscriptions < ActiveRecord::Migration[5.0] + def change + add_column :subscriptions, :last_successful_delivery_at, :datetime, null: true, default: nil + end +end diff --git a/db/schema.rb b/db/schema.rb index 2c0e6de5bc..9ba638bfc2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161128103007) do +ActiveRecord::Schema.define(version: 20161130142058) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -199,13 +199,14 @@ ActiveRecord::Schema.define(version: 20161128103007) do end create_table "subscriptions", force: :cascade do |t| - t.string "callback_url", default: "", null: false + t.string "callback_url", default: "", null: false t.string "secret" t.datetime "expires_at" - t.boolean "confirmed", default: false, null: false - t.integer "account_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.boolean "confirmed", default: false, null: false + t.integer "account_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.datetime "last_successful_delivery_at" t.index ["callback_url", "account_id"], name: "index_subscriptions_on_callback_url_and_account_id", unique: true, using: :btree end