mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
creates models open_api client and calls_count_tracing, adds worker to trace calls count
This commit is contained in:
parent
ff316f7bdd
commit
92b3471032
2
Gemfile
2
Gemfile
@ -139,3 +139,5 @@ gem 'protected_attributes'
|
|||||||
gem 'message_format'
|
gem 'message_format'
|
||||||
|
|
||||||
gem 'openlab_ruby'
|
gem 'openlab_ruby'
|
||||||
|
|
||||||
|
gem 'has_secure_token'
|
||||||
|
@ -164,6 +164,8 @@ GEM
|
|||||||
activerecord (>= 4.0.0)
|
activerecord (>= 4.0.0)
|
||||||
globalid (0.3.6)
|
globalid (0.3.6)
|
||||||
activesupport (>= 4.1.0)
|
activesupport (>= 4.1.0)
|
||||||
|
has_secure_token (1.0.0)
|
||||||
|
activerecord (>= 3.0)
|
||||||
hashdiff (0.3.0)
|
hashdiff (0.3.0)
|
||||||
hashie (3.4.2)
|
hashie (3.4.2)
|
||||||
highline (1.7.1)
|
highline (1.7.1)
|
||||||
@ -452,6 +454,7 @@ DEPENDENCIES
|
|||||||
foreman
|
foreman
|
||||||
forgery
|
forgery
|
||||||
friendly_id (~> 5.1.0)
|
friendly_id (~> 5.1.0)
|
||||||
|
has_secure_token
|
||||||
jbuilder (~> 2.0)
|
jbuilder (~> 2.0)
|
||||||
jquery-rails
|
jquery-rails
|
||||||
kaminari
|
kaminari
|
||||||
|
5
app/models/open_api.rb
Normal file
5
app/models/open_api.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module OpenAPI
|
||||||
|
def self.table_name_prefix
|
||||||
|
'open_api_'
|
||||||
|
end
|
||||||
|
end
|
4
app/models/open_api/calls_count_tracing.rb
Normal file
4
app/models/open_api/calls_count_tracing.rb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
class OpenAPI::CallsCountTracing < ActiveRecord::Base
|
||||||
|
belongs_to :client, foreign_key: :open_api_client_id
|
||||||
|
validates :client, :at, presence: true
|
||||||
|
end
|
9
app/models/open_api/client.rb
Normal file
9
app/models/open_api/client.rb
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
class OpenAPI::Client < ActiveRecord::Base
|
||||||
|
has_many :calls_count_tracings, foreign_key: :open_api_client_id, dependent: :destroy
|
||||||
|
has_secure_token
|
||||||
|
validates :name, presence: true
|
||||||
|
|
||||||
|
def increment_calls_count
|
||||||
|
update_column(:calls_count, calls_count+1)
|
||||||
|
end
|
||||||
|
end
|
1
app/models/open_api/parameter_error.rb
Normal file
1
app/models/open_api/parameter_error.rb
Normal file
@ -0,0 +1 @@
|
|||||||
|
class OpenAPI::ParameterError < StandardError; end
|
10
app/workers/open_api_trace_calls_count_worker.rb
Normal file
10
app/workers/open_api_trace_calls_count_worker.rb
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
class OpenAPITraceCallsCountWorker < ActiveJob::Base
|
||||||
|
include Sidekiq::Worker
|
||||||
|
sidekiq_options queue: 'default', retry: true
|
||||||
|
|
||||||
|
def perform
|
||||||
|
OpenAPI::Client.find_each do |client|
|
||||||
|
OpenAPI::CallsCountTracing.create!(client: client, calls_count: client.calls_count, at: DateTime.now)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -14,3 +14,7 @@ generate_statistic:
|
|||||||
cron: "0 1 * * *"
|
cron: "0 1 * * *"
|
||||||
class: "StatisticWorker"
|
class: "StatisticWorker"
|
||||||
queue: default
|
queue: default
|
||||||
|
|
||||||
|
open_api_trace_calls_count:
|
||||||
|
cron: "0 4 * * 0" # every sunday at 4am
|
||||||
|
class: "OpenAPITraceCallsCountWorker"
|
||||||
|
10
db/migrate/20160504085703_create_open_api_clients.rb
Normal file
10
db/migrate/20160504085703_create_open_api_clients.rb
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
class CreateOpenAPIClients < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :open_api_clients do |t|
|
||||||
|
t.string :name
|
||||||
|
t.integer :calls_count, default: 0
|
||||||
|
t.string :token
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,10 @@
|
|||||||
|
class CreateOpenAPICallsCountTracings < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :open_api_calls_count_tracings do |t|
|
||||||
|
t.belongs_to :open_api_client, foreign_key: true, index: true
|
||||||
|
t.integer :calls_count, null: false
|
||||||
|
t.datetime :at, null: false
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
21
db/schema.rb
21
db/schema.rb
@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20160119131623) do
|
ActiveRecord::Schema.define(version: 20160504085905) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@ -267,6 +267,24 @@ ActiveRecord::Schema.define(version: 20160119131623) do
|
|||||||
|
|
||||||
add_index "offer_days", ["subscription_id"], name: "index_offer_days_on_subscription_id", using: :btree
|
add_index "offer_days", ["subscription_id"], name: "index_offer_days_on_subscription_id", using: :btree
|
||||||
|
|
||||||
|
create_table "open_api_calls_count_tracings", force: :cascade do |t|
|
||||||
|
t.integer "open_api_client_id"
|
||||||
|
t.integer "calls_count", null: false
|
||||||
|
t.datetime "at", null: false
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "open_api_calls_count_tracings", ["open_api_client_id"], name: "index_open_api_calls_count_tracings_on_open_api_client_id", using: :btree
|
||||||
|
|
||||||
|
create_table "open_api_clients", force: :cascade do |t|
|
||||||
|
t.string "name"
|
||||||
|
t.integer "calls_count", default: 0
|
||||||
|
t.string "token"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
create_table "plans", force: :cascade do |t|
|
create_table "plans", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.integer "amount"
|
t.integer "amount"
|
||||||
@ -643,6 +661,7 @@ ActiveRecord::Schema.define(version: 20160119131623) do
|
|||||||
add_foreign_key "availability_tags", "availabilities"
|
add_foreign_key "availability_tags", "availabilities"
|
||||||
add_foreign_key "availability_tags", "tags"
|
add_foreign_key "availability_tags", "tags"
|
||||||
add_foreign_key "o_auth2_mappings", "o_auth2_providers"
|
add_foreign_key "o_auth2_mappings", "o_auth2_providers"
|
||||||
|
add_foreign_key "open_api_calls_count_tracings", "open_api_clients"
|
||||||
add_foreign_key "prices", "groups"
|
add_foreign_key "prices", "groups"
|
||||||
add_foreign_key "prices", "plans"
|
add_foreign_key "prices", "plans"
|
||||||
add_foreign_key "user_tags", "tags"
|
add_foreign_key "user_tags", "tags"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user