asyncapi-client 0.2.0 → 0.3.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: 13ebb832003a17b09de81bdfb57189642d7fcadc
4
- data.tar.gz: 138494b7d2eb080eaab93682140874b57b3737b6
3
+ metadata.gz: cab20cbbe30a21d0b85d178847743113ec9396f0
4
+ data.tar.gz: f7a5d27f8b8c1389a238d70a749da18e11f6dc3c
5
5
  SHA512:
6
- metadata.gz: ea09a451882fb31a7d9c2ed01f1f111b853bf2bc61e1a513266767ea0ce9d35ab242e08168d771b3690696ac572641660b2bbaefff5ac60598d94b7aa0531bc8
7
- data.tar.gz: ead656b31c998c890eb930133aa27f50cdc457c35b6b0ba50c115ecb4c113bdff2b5077809b53c3978ec4d87c7185f39592f5853779d62272d64443a7dff752b
6
+ metadata.gz: 4ba00f9669e29ca8286eb426bcf1614258a37bcf851669f63896f5347dd9f3a374dee330bc04277fc4cb079655ae45964118a67d7e76c8106c30269c2310b784
7
+ data.tar.gz: 03005f2e7dd1d16d512dd9bb3e5990329a5bebcaace342a33919c0ecf47abe44627e681936eeac821ee6e0877557d9bcfd2220371e60824696a6a5f2d8495ae4
data/README.md CHANGED
@@ -17,6 +17,7 @@ Asyncapi::Client::Job.post(
17
17
  on_success: DoOnSuccess,
18
18
  on_error: DoOnError,
19
19
  on_queue: DoOnQueue,
20
+ on_queue_error: DoOnQueueError,
20
21
  on_time_out: DoOnTimeOut,
21
22
  time_out: 2.minutes # Defaults to nil (never time out)
22
23
  )
@@ -42,7 +43,7 @@ end
42
43
 
43
44
  class DoOnError < Asyncapi::Client::CallbackRunner
44
45
  def call
45
- # you have access to: job and it fields: callback_params, :body, :headers, :message
46
+ # you have access to: job and its fields: callback_params, :body, :headers, :message, :response_code
46
47
  Rails.logger.info "Job##{job.id} failed. The server's response: #{job.message}"
47
48
  end
48
49
  end
@@ -54,6 +55,7 @@ In the callback classes, you have access to the `job` and its fields (directly):
54
55
  - `body`
55
56
  - `headers`
56
57
  - `message`
58
+ - `response_code`
57
59
 
58
60
  Currently, this Engine only works with [Sidekiq](http://sidekiq.org), [typhoeus](https://github.com/typhoeus/typhoeus), and [kaminari](https://github.com/amatsuda/kaminari). Customizing these can be introduced as needed.
59
61
 
@@ -119,9 +121,11 @@ Asyncapi::Client::Job.attr_accessible(
119
121
  :on_queue,
120
122
  :on_success,
121
123
  :on_error,
124
+ :on_queue_error,
122
125
  :headers,
123
126
  :body,
124
127
  :status,
128
+ :response_code,
125
129
  )
126
130
  ```
127
131
 
@@ -7,6 +7,7 @@ module Asyncapi::Client
7
7
  :body,
8
8
  :headers,
9
9
  :message,
10
+ :response_code,
10
11
  ]
11
12
  delegate *DELEGATED_ATTRS, to: :job
12
13
 
@@ -4,7 +4,7 @@ module Asyncapi::Client
4
4
  after_initialize :generate_secret
5
5
  before_create :set_expired_at
6
6
 
7
- enum status: %i[queued success error timed_out fresh]
7
+ enum status: %i[queued success error timed_out fresh queue_error]
8
8
  serialize :headers, Hash
9
9
  serialize :callback_params, Hash
10
10
 
@@ -15,6 +15,7 @@ module Asyncapi::Client
15
15
  state :success
16
16
  state :error
17
17
  state :timed_out
18
+ state :queue_error
18
19
 
19
20
  event :enqueue do
20
21
  transitions from: :fresh, to: :queued
@@ -31,12 +32,17 @@ module Asyncapi::Client
31
32
  event :time_out do
32
33
  transitions from: [:fresh, :queued], to: :timed_out
33
34
  end
35
+
36
+ event :fail_queue do
37
+ transitions from: :fresh, to: :queue_error
38
+ end
34
39
  end
35
40
 
36
41
  scope :expired, -> { where(arel_table[:expired_at].lt(Time.now)) }
37
42
  scope :with_time_out, -> { where(arel_table[:time_out_at].not_eq(nil)) }
38
43
  scope :for_time_out, -> do
39
- with_time_out.where(arel_table[:time_out_at].lt(Time.now))
44
+ where(arel_table[:time_out_at].lt(Time.now)).
45
+ where(status: [statuses[:queued], statuses[:fresh]])
40
46
  end
41
47
 
42
48
  def self.post(url,
@@ -46,6 +52,7 @@ module Asyncapi::Client
46
52
  on_success: nil,
47
53
  on_error: nil,
48
54
  on_time_out: nil,
55
+ on_queue_error: nil,
49
56
  callback_params: {},
50
57
  follow_up: 5.minutes,
51
58
  time_out: nil)
@@ -55,6 +62,7 @@ module Asyncapi::Client
55
62
  on_queue: on_queue,
56
63
  on_success: on_success,
57
64
  on_error: on_error,
65
+ on_queue_error: on_queue_error,
58
66
  on_time_out: on_time_out,
59
67
  callback_params: callback_params,
60
68
  headers: headers,
@@ -75,7 +83,7 @@ module Asyncapi::Client
75
83
  write_attribute :body, json
76
84
  end
77
85
 
78
- [:on_success, :on_error, :on_queue, :on_time_out].each do |attr|
86
+ [:on_success, :on_error, :on_queue, :on_time_out, :on_queue_error].each do |attr|
79
87
  define_method("#{attr}=") do |klass|
80
88
  write_attribute attr, klass.to_s
81
89
  end
@@ -91,5 +99,15 @@ module Asyncapi::Client
91
99
  self.secret ||= SecureRandom.uuid
92
100
  end
93
101
 
102
+ def self.initial_state
103
+ self.aasm.state_machine.initial_state
104
+ end
105
+
106
+ def self.non_initial_states
107
+ self.aasm.states.reject do |state|
108
+ state == initial_state
109
+ end.map(&:name)
110
+ end
111
+
94
112
  end
95
113
  end
@@ -24,7 +24,8 @@ module Asyncapi::Client
24
24
  JobStatusWorker.perform_async(job.id)
25
25
  end
26
26
  else
27
- if job.update_attributes(status: :error, message: response.body)
27
+ job.fail_queue
28
+ if job.update_attributes!(message: response.body, response_code: response.response_code)
28
29
  JobStatusWorker.perform_async(job.id)
29
30
  end
30
31
  end
@@ -33,7 +34,7 @@ module Asyncapi::Client
33
34
  def job_params_from(response)
34
35
  response_body = JSON.parse(response.body).with_indifferent_access
35
36
  server_job_params = response_body[:job]
36
- {server_job_url: server_job_params[:url]}
37
+ {server_job_url: server_job_params[:url], response_code: response.response_code}
37
38
  end
38
39
 
39
40
  def server_params_from(job, params)
@@ -9,6 +9,7 @@ module Asyncapi::Client
9
9
  success: :on_success,
10
10
  error: :on_error,
11
11
  timed_out: :on_time_out,
12
+ queue_error: :on_queue_error,
12
13
  }.with_indifferent_access
13
14
 
14
15
  def perform(job_id)
@@ -9,9 +9,7 @@ module Asyncapi::Client
9
9
  recurrence { minutely }
10
10
 
11
11
  def perform
12
- Job.for_time_out.find_each do |job|
13
- time_out_job(job) if job.may_time_out?
14
- end
12
+ Job.for_time_out.find_each { |job| time_out_job(job) }
15
13
  end
16
14
 
17
15
  private
@@ -0,0 +1,5 @@
1
+ class AddResponseCodeToAsyncapiClientJobs < ActiveRecord::Migration
2
+ def change
3
+ add_column :asyncapi_client_jobs, :response_code, :integer
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddOnQueueErrorToAsyncapiClientJobs < ActiveRecord::Migration
2
+ def change
3
+ add_column :asyncapi_client_jobs, :on_queue_error, :string
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module Asyncapi
2
2
  module Client
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
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.2.0
4
+ version: 0.3.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: 2015-06-29 00:00:00.000000000 Z
13
+ date: 2015-09-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -251,6 +251,8 @@ files:
251
251
  - db/migrate/20150202062320_populate_asyncapi_client_job_expired_at.rb
252
252
  - db/migrate/20150610053320_add_on_time_out_to_asyncapi_client_job.rb
253
253
  - db/migrate/20150612082965_add_time_out_index_to_asyncapi_client_job.rb
254
+ - db/migrate/20150630004215_add_response_code_to_asyncapi_client_jobs.rb
255
+ - db/migrate/20150703001225_add_on_queue_error_to_asyncapi_client_jobs.rb
254
256
  - lib/asyncapi-client.rb
255
257
  - lib/asyncapi/client.rb
256
258
  - lib/asyncapi/client/engine.rb
@@ -278,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
278
280
  version: '0'
279
281
  requirements: []
280
282
  rubyforge_project:
281
- rubygems_version: 2.4.5
283
+ rubygems_version: 2.4.8
282
284
  signing_key:
283
285
  specification_version: 4
284
286
  summary: Asynchronous API communication