asyncapi-client 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f87f6926b827e5fd13e149f5c8be271bc403b70b
4
- data.tar.gz: b069c2ad36fd138d81749e5043bf759b622f7cae
3
+ metadata.gz: bb359e773a03ebfdcf520583dd45c19dd8fdbc53
4
+ data.tar.gz: aacd73eb3244465fa8d68b37ca784ff994e56fc0
5
5
  SHA512:
6
- metadata.gz: 95f6229083351515c521543934569a93e2b6c83c92f2237d9ca47d382b76fc210532932796e40478b4bedebb7932f4774303a8834a0f0d0ff2f6df8151698903
7
- data.tar.gz: 79dd9e24681b251dd0bc34c266a4faf2dea526be886c734952ec1f444555c0f4ca6f5baf6e5350e73369af63950e847983a3d0e9873364e446d6f24843c03161
6
+ metadata.gz: eb344d71daa7c95cb318da4280b051a2f84c93caa2d17a1935df78b62e54f0e6625068cf8aa99eceacd898900151d152a118ad236f4df3cb77eef13f62669ad3
7
+ data.tar.gz: b7b6fea653dacf7bc0b936ad098a6e49ce98b30ffa6e7328e8ac78b7bc1684b9b025f8eb6ea2377695c60c2c4501ab706939faa9166e1f653e36c82a9eb3fd44
@@ -6,9 +6,7 @@ module Asyncapi
6
6
  sidekiq_options retry: false
7
7
 
8
8
  def perform
9
- Job.expired.find_each do |job|
10
- JobCleanerWorker.perform_async(job.id)
11
- end
9
+ Job.expired.pluck(:id).each{ |job_id| JobCleanerWorker.perform_async(job_id) }
12
10
  end
13
11
 
14
12
  end
@@ -7,7 +7,7 @@ module Asyncapi
7
7
 
8
8
  def perform(job_id)
9
9
  if job = Job.find_by(id: job_id)
10
- destroy_remote job
10
+ destroy_remote(job)
11
11
  job.destroy
12
12
  end
13
13
  end
@@ -15,12 +15,46 @@ module Asyncapi
15
15
  private
16
16
 
17
17
  def destroy_remote(job)
18
- Typhoeus.delete(job.server_job_url, {
19
- params: { secret: job.secret },
20
- headers: job.headers,
21
- })
18
+ errors = validate_remote_job_info(job)
19
+ if errors.empty?
20
+ Typhoeus.delete(job.server_job_url, {
21
+ params: { secret: job.secret },
22
+ headers: job.headers,
23
+ })
24
+ else
25
+ log_remote_error_for(job, errors)
26
+ end
27
+ end
28
+
29
+ def validate_remote_job_info(job)
30
+ errors = []
31
+ errors << "server_job_url is invalid" unless url_ok_for?(job)
32
+ errors << "authorization headers are not present" unless headers_ok_for?(job)
33
+ errors << "secret is not present" unless job.secret.present?
34
+ errors
35
+ end
36
+
37
+ def url_ok_for?(job)
38
+ uri = URI.parse(job.server_job_url)
39
+ uri.is_a?(URI::HTTP) && !uri.host.nil?
40
+ rescue URI::InvalidURIError
41
+ false
22
42
  end
23
43
 
44
+ def headers_ok_for?(job)
45
+ job.headers.is_a?(Hash) && job.headers[:AUTHORIZATION]
46
+ end
47
+
48
+ def log_remote_error_for(job, errors)
49
+ if defined?(G5::Logger::Log)
50
+ G5::Logger::Log.send(:warn, {
51
+ origin: "#{self.class.name}#destroy_remote",
52
+ external_parent_id: "#{job.id}",
53
+ message: "Not enough info to delete expired remote job: #{errors.join(", ")}",
54
+ error: "Unable to delete remote job",
55
+ })
56
+ end
57
+ end
24
58
  end
25
59
  end
26
60
  end
@@ -1,4 +1,4 @@
1
- class CreateAsyncapiClientJobs < ActiveRecord::Migration
1
+ class CreateAsyncapiClientJobs < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table :asyncapi_client_jobs do |t|
4
4
  t.string "server_job_url"
@@ -1,4 +1,4 @@
1
- class AddCallbackParamsToAsyncapiClientJobs < ActiveRecord::Migration
1
+ class AddCallbackParamsToAsyncapiClientJobs < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_column :asyncapi_client_jobs, :callback_params, :text
4
4
  end
@@ -1,4 +1,4 @@
1
- class AddSecretToAsyncapiClientJob < ActiveRecord::Migration
1
+ class AddSecretToAsyncapiClientJob < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_column :asyncapi_client_jobs, :secret, :string
4
4
  end
@@ -1,4 +1,4 @@
1
- class AddExpiredAtToAsyncapiClientJob < ActiveRecord::Migration
1
+ class AddExpiredAtToAsyncapiClientJob < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_column :asyncapi_client_jobs, :expired_at, :datetime
4
4
  end
@@ -1,4 +1,4 @@
1
- class PopulateAsyncapiClientJobExpiredAt < ActiveRecord::Migration
1
+ class PopulateAsyncapiClientJobExpiredAt < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  Asyncapi::Client::Job.find_each do |job|
4
4
  job.update_attributes(expired_at: Asyncapi::Client.expiry_threshold.from_now)
@@ -1,4 +1,4 @@
1
- class AddOnTimeOutToAsyncapiClientJob < ActiveRecord::Migration
1
+ class AddOnTimeOutToAsyncapiClientJob < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_column :asyncapi_client_jobs, :on_time_out, :string
4
4
  end
@@ -1,4 +1,4 @@
1
- class AddTimeOutIndexToAsyncapiClientJob < ActiveRecord::Migration
1
+ class AddTimeOutIndexToAsyncapiClientJob < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_index :asyncapi_client_jobs, :time_out_at
4
4
  end
@@ -1,4 +1,4 @@
1
- class AddResponseCodeToAsyncapiClientJobs < ActiveRecord::Migration
1
+ class AddResponseCodeToAsyncapiClientJobs < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_column :asyncapi_client_jobs, :response_code, :integer
4
4
  end
@@ -1,4 +1,4 @@
1
- class AddOnQueueErrorToAsyncapiClientJobs < ActiveRecord::Migration
1
+ class AddOnQueueErrorToAsyncapiClientJobs < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_column :asyncapi_client_jobs, :on_queue_error, :string
4
4
  end
@@ -0,0 +1,11 @@
1
+ class AddExpiredAtIndexToAsyncapiClientJobs < ActiveRecord::Migration[5.0]
2
+ disable_ddl_transaction!
3
+
4
+ def change
5
+ opts = {}
6
+ if !!(ActiveRecord::Base.connection_config[:adapter] =~ /postgresql/i)
7
+ opts[:algorithm] = :concurrently
8
+ end
9
+ add_index :asyncapi_client_jobs, :expired_at, opts
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module Asyncapi
2
2
  module Client
3
- VERSION = "0.7.0"
3
+ VERSION = "0.8.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asyncapi-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - G5
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-04-03 00:00:00.000000000 Z
13
+ date: 2019-02-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -128,16 +128,16 @@ dependencies:
128
128
  name: sqlite3
129
129
  requirement: !ruby/object:Gem::Requirement
130
130
  requirements:
131
- - - ">="
131
+ - - "~>"
132
132
  - !ruby/object:Gem::Version
133
- version: '0'
133
+ version: 1.3.6
134
134
  type: :development
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
137
137
  requirements:
138
- - - ">="
138
+ - - "~>"
139
139
  - !ruby/object:Gem::Version
140
- version: '0'
140
+ version: 1.3.6
141
141
  - !ruby/object:Gem::Dependency
142
142
  name: rspec-rails
143
143
  requirement: !ruby/object:Gem::Requirement
@@ -267,6 +267,7 @@ files:
267
267
  - db/migrate/20150612082965_add_time_out_index_to_asyncapi_client_job.rb
268
268
  - db/migrate/20150630004215_add_response_code_to_asyncapi_client_jobs.rb
269
269
  - db/migrate/20150703001225_add_on_queue_error_to_asyncapi_client_jobs.rb
270
+ - db/migrate/20190218200630_add_expired_at_index_to_asyncapi_client_jobs.rb
270
271
  - lib/asyncapi-client.rb
271
272
  - lib/asyncapi/client.rb
272
273
  - lib/asyncapi/client/engine.rb