asyncapi-client 0.8.0 → 0.11.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
- SHA1:
3
- metadata.gz: bb359e773a03ebfdcf520583dd45c19dd8fdbc53
4
- data.tar.gz: aacd73eb3244465fa8d68b37ca784ff994e56fc0
2
+ SHA256:
3
+ metadata.gz: 5fd1ef047e069d51524a6d6fa1a935dd21291f9287314f9c0cecedd06a4443be
4
+ data.tar.gz: 2103154fa8afb427645b952aa63e1503819ea961d38d0899e5efe5c01ed4b972
5
5
  SHA512:
6
- metadata.gz: eb344d71daa7c95cb318da4280b051a2f84c93caa2d17a1935df78b62e54f0e6625068cf8aa99eceacd898900151d152a118ad236f4df3cb77eef13f62669ad3
7
- data.tar.gz: b7b6fea653dacf7bc0b936ad098a6e49ce98b30ffa6e7328e8ac78b7bc1684b9b025f8eb6ea2377695c60c2c4501ab706939faa9166e1f653e36c82a9eb3fd44
6
+ metadata.gz: a012d3e92b0955d0d35e520441eb2d17798740366c410e319a33f595826ab1368ceb197a4ae27995d7610b2aceb5a644820b96488b0551203506e1f535a36d65
7
+ data.tar.gz: 41a1a7a745dc6e67fb9097dedb1f97c4f3cf03e3ab97378567f0bbc7023bf7283cc83fd36fef2c0a6f6ebc08a556f9bee1eaf48200d13123038faa6de90c2bf2
data/README.md CHANGED
@@ -73,9 +73,11 @@ There is a feed of all jobs that can be accessed via `/asyncapi/client/v1/jobs.j
73
73
 
74
74
  ## Expiry
75
75
 
76
- To make space in the database, old jobs must be deleted. By default, jobs older than 10 days will be deleted in both the Asyncapi Client and Asyncapi Server. Asyncapi Client is responsible for deleting the jobs it no longer needs a response from on the server.
76
+ To make space in the database, old jobs must be deleted. By default, jobs older than 4 days will be deleted in both the Asyncapi Client and Asyncapi Server. Asyncapi Client is responsible for deleting the jobs it no longer needs a response from on the server.
77
77
 
78
- By default, jobs 10 days old and older will be deleted. You can change this setting by putting this in an initializer:
78
+ **Important:** keep in mind that this setting may conflict with the `successful_jobs_deletion_after` setting with jobs in `success` state, which normally are deleted after they reach this state (see [Successful jobs automatic deletion](#successful-jobs-automatic-deletion) for more information).
79
+
80
+ By default, jobs 4 days old and older will be deleted. You can change this setting by putting this in an initializer:
79
81
 
80
82
  ```ruby
81
83
  Asyncapi::Client.expiry_threshold = 5.days
@@ -89,6 +91,16 @@ The cleaner job is run every day at "0 0 * * *". If you want to change the frequ
89
91
  Asyncapi::Client.clean_job_cron = "30 2 * * *"
90
92
  ```
91
93
 
94
+ ## Successful jobs automatic deletion
95
+
96
+ After a job completes successfully, we schedule another job to delete it after a brief period of time to avoid having a lot of records on the table. By default, a successful job is deleted from the table after 2 minutes, ignoring the `expiry_threshold` configuration option. You can change this setting using the `successful_jobs_deletion_after` configuration option in an initializer if you want to extend or shorten the wait time for deletion:
97
+
98
+ ```ruby
99
+ Asyncapi::Client.successful_jobs_deletion_after = 3.days
100
+ ```
101
+
102
+ **Important:** if you want to ignore `successful_jobs_deletion_after` setting in favor of `expiry_threshold`, set `successful_jobs_deletion_after` to a value greater than `expiry_threshold`.
103
+
92
104
  # Installation
93
105
 
94
106
  **Note**: if you're using the `protected_attributes`, also see the "Optional" section below.
@@ -21,7 +21,7 @@ module Asyncapi::Client
21
21
  transitions from: :fresh, to: :queued
22
22
  end
23
23
 
24
- event :succeed do
24
+ event :succeed, after: :schedule_for_deletion do
25
25
  transitions from: :queued, to: :success
26
26
  end
27
27
 
@@ -40,6 +40,10 @@ module Asyncapi::Client
40
40
 
41
41
  scope :expired, -> { where(arel_table[:expired_at].lt(Time.now)) }
42
42
  scope :with_time_out, -> { where(arel_table[:time_out_at].not_eq(nil)) }
43
+ scope :stale, -> (stale_duration = 5) do
44
+ where(arel_table[:updated_at].lteq(stale_duration.minutes.ago)).
45
+ where(status: statuses[:queued])
46
+ end
43
47
  scope :for_time_out, -> do
44
48
  where(arel_table[:time_out_at].lt(Time.now)).
45
49
  where(status: [statuses[:queued], statuses[:fresh]])
@@ -87,6 +91,13 @@ module Asyncapi::Client
87
91
 
88
92
  private
89
93
 
94
+ def schedule_for_deletion
95
+ if success?
96
+ # delete in a couple of minutes, giving time for the success to be broadcasted
97
+ JobCleanerWorker.perform_in(Asyncapi::Client.successful_jobs_deletion_after, self.id)
98
+ end
99
+ end
100
+
90
101
  def set_expired_at
91
102
  self.expired_at ||= Asyncapi::Client.expiry_threshold.from_now
92
103
  end
@@ -12,7 +12,7 @@ module Asyncapi::Client
12
12
  private
13
13
 
14
14
  def time_out_job(job)
15
- job.update_attributes(status: :timed_out)
15
+ job.update(status: :timed_out)
16
16
  ActiveRecord::Base.after_transaction do
17
17
  JobStatusWorker.perform_async(job.id)
18
18
  end
@@ -0,0 +1,5 @@
1
+ class RemoveExpiredAtIndexOnAsyncapiClientJobs < ActiveRecord::Migration[5.0]
2
+ def change
3
+ remove_index :asyncapi_client_jobs, :expired_at
4
+ end
5
+ end
@@ -10,9 +10,10 @@ require "securerandom"
10
10
  module Asyncapi
11
11
  module Client
12
12
 
13
- CONFIG_ATTRS = %i[parent_controller expiry_threshold clean_job_cron]
13
+ CONFIG_ATTRS = %i[parent_controller expiry_threshold clean_job_cron successful_jobs_deletion_after]
14
14
  mattr_accessor(*CONFIG_ATTRS)
15
- self.expiry_threshold = 10.days
15
+ self.expiry_threshold = 4.days
16
+ self.successful_jobs_deletion_after = 2.minutes
16
17
  self.clean_job_cron = "0 0 * * *"
17
18
 
18
19
  def self.configure
@@ -1,5 +1,5 @@
1
1
  module Asyncapi
2
2
  module Client
3
- VERSION = "0.8.0".freeze
3
+ VERSION = "0.11.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asyncapi-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - G5
8
8
  - Marc Ignacio
9
9
  - Ramon Tayag
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-02-27 00:00:00.000000000 Z
13
+ date: 2021-06-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: '5.0'
21
+ version: '6.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: '5.0'
28
+ version: '6.0'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: sidekiq
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -124,20 +124,34 @@ dependencies:
124
124
  - - ">="
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: sprockets
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - "<"
132
+ - !ruby/object:Gem::Version
133
+ version: '4'
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - "<"
139
+ - !ruby/object:Gem::Version
140
+ version: '4'
127
141
  - !ruby/object:Gem::Dependency
128
142
  name: sqlite3
129
143
  requirement: !ruby/object:Gem::Requirement
130
144
  requirements:
131
145
  - - "~>"
132
146
  - !ruby/object:Gem::Version
133
- version: 1.3.6
147
+ version: 1.4.2
134
148
  type: :development
135
149
  prerelease: false
136
150
  version_requirements: !ruby/object:Gem::Requirement
137
151
  requirements:
138
152
  - - "~>"
139
153
  - !ruby/object:Gem::Version
140
- version: 1.3.6
154
+ version: 1.4.2
141
155
  - !ruby/object:Gem::Dependency
142
156
  name: rspec-rails
143
157
  requirement: !ruby/object:Gem::Requirement
@@ -268,6 +282,7 @@ files:
268
282
  - db/migrate/20150630004215_add_response_code_to_asyncapi_client_jobs.rb
269
283
  - db/migrate/20150703001225_add_on_queue_error_to_asyncapi_client_jobs.rb
270
284
  - db/migrate/20190218200630_add_expired_at_index_to_asyncapi_client_jobs.rb
285
+ - db/migrate/20190304200630_remove_expired_at_index_on_asyncapi_client_jobs.rb
271
286
  - lib/asyncapi-client.rb
272
287
  - lib/asyncapi/client.rb
273
288
  - lib/asyncapi/client/engine.rb
@@ -279,7 +294,7 @@ homepage: https://github.com/G5/asyncapi-client
279
294
  licenses:
280
295
  - MIT
281
296
  metadata: {}
282
- post_install_message:
297
+ post_install_message:
283
298
  rdoc_options: []
284
299
  require_paths:
285
300
  - lib
@@ -294,9 +309,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
294
309
  - !ruby/object:Gem::Version
295
310
  version: '0'
296
311
  requirements: []
297
- rubyforge_project:
298
- rubygems_version: 2.5.1
299
- signing_key:
312
+ rubygems_version: 3.0.9
313
+ signing_key:
300
314
  specification_version: 4
301
315
  summary: Asynchronous API communication
302
316
  test_files: []