asyncapi-client 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -8
- data/app/models/asyncapi/client/job.rb +0 -1
- data/app/workers/asyncapi/client/cleaner_worker.rb +8 -0
- data/lib/asyncapi/client.rb +2 -1
- data/lib/asyncapi/client/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c4aa942b90ab8794c0eaeb572810d4277581df5
|
4
|
+
data.tar.gz: 186bd9cf4144c883d8f532e18caa8bd5143c2755
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6553230b72635076b4fee02bb0a47fd04b50821c6ddae57f3819bc353f33289c151eadbfe5fbcd8be0a58cb8e36f07d28209e7684ffee3aef7c6c82876c5e1a1
|
7
|
+
data.tar.gz: a4358536d0282459c8830a2009b761d60d008ea5dfdfa6c7be598edd75c5effa8629b18ccfd583c18f323b24974c2beedbeab90caf94c4a6c28f065e0e66ed0a
|
data/README.md
CHANGED
@@ -2,7 +2,11 @@
|
|
2
2
|
|
3
3
|
Asyncapi::Client is a Rails engine that easily allows asynchronous communication with a [Asyncapi::Server](https://github.com/G5/asyncapi-server)-based API server.
|
4
4
|
|
5
|
-
|
5
|
+
The common pattern that this gem saves you from implementing for the service callback pattern. [soapatterns.org](http://soapatterns.org/design_patterns/service_callback) describes it well, and [this image they provide](http://soapatterns.org/static/images/figures/service_callback/fig1.png) summarizes it:
|
6
|
+
|
7
|
+
![Service Callback Pattern](docs/service-callback-pattern.png)
|
8
|
+
|
9
|
+
Implementing this typically requires a bunch of code that looks the same: HTTP posts, receive hooks - all while the data that's passed around different.
|
6
10
|
|
7
11
|
# Usage
|
8
12
|
|
@@ -23,14 +27,19 @@ Asyncapi::Client::Job.post(
|
|
23
27
|
)
|
24
28
|
```
|
25
29
|
|
26
|
-
|
30
|
+
Here is a breakdown of what these parameters mean:
|
27
31
|
|
28
|
-
|
32
|
+
- `http://server.com/long/running/process`: this is an endpoint that you will create using [Asyncapi::Server](https://github.com/G5/asyncapi-server)
|
33
|
+
- `body`: any data you want to send to the server that's needed for it to do its work
|
34
|
+
- `headers`: if needed, headers for authorization, for example
|
35
|
+
- `on_success`, `on_error`, `on_*`: service objects that will get executed whenever these events occur. More on this below.
|
36
|
+
- `time_out`: when this job should be considered timed out. This is helpful when you want to know if the server ever got to working on the job. Jobs that should be timed out are marked as `timed_out` approximately every minute.
|
37
|
+
|
38
|
+
## `on_*` Callbacks
|
29
39
|
|
30
40
|
```ruby
|
31
41
|
class DoOnQueue < Asyncapi::Client::CallbackRunner
|
32
42
|
def call
|
33
|
-
# you have access to: job, callback_params
|
34
43
|
Rails.logger.info "Job##{job.id} successfully queued with body: #{job.body}"
|
35
44
|
end
|
36
45
|
end
|
@@ -43,13 +52,12 @@ end
|
|
43
52
|
|
44
53
|
class DoOnError < Asyncapi::Client::CallbackRunner
|
45
54
|
def call
|
46
|
-
# you have access to: job and its fields: callback_params, :body, :headers, :message, :response_code
|
47
55
|
Rails.logger.info "Job##{job.id} failed. The server's response: #{job.message}"
|
48
56
|
end
|
49
57
|
end
|
50
58
|
```
|
51
59
|
|
52
|
-
In the callback
|
60
|
+
In the callback service objects, you have access to the `job` and its fields (directly):
|
53
61
|
|
54
62
|
- `callback_params`
|
55
63
|
- `body`
|
@@ -57,7 +65,7 @@ In the callback classes, you have access to the `job` and its fields (directly):
|
|
57
65
|
- `message`
|
58
66
|
- `response_code`
|
59
67
|
|
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.
|
68
|
+
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 to this gem as needed.
|
61
69
|
|
62
70
|
To run the application, you need to have the Sidekiq workers running as well.
|
63
71
|
|
@@ -73,7 +81,13 @@ By default, jobs 10 days old and older will be deleted. You can change this sett
|
|
73
81
|
Asyncapi::Client.expiry_threshold = 5.days
|
74
82
|
```
|
75
83
|
|
76
|
-
If you don't
|
84
|
+
If you don't want the jobs to get deleted, set the threshold to `nil`.
|
85
|
+
|
86
|
+
The cleaner job is run every day at "0 0 * * *". If you want to change the frequency that this runs, then:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
Asyncapi::Client.clean_job_cron = "30 2 * * *"
|
90
|
+
```
|
77
91
|
|
78
92
|
# Installation
|
79
93
|
|
data/lib/asyncapi/client.rb
CHANGED
@@ -9,9 +9,10 @@ require "securerandom"
|
|
9
9
|
module Asyncapi
|
10
10
|
module Client
|
11
11
|
|
12
|
-
CONFIG_ATTRS = [
|
12
|
+
CONFIG_ATTRS = %i[parent_controller expiry_threshold clean_job_cron]
|
13
13
|
mattr_accessor(*CONFIG_ATTRS)
|
14
14
|
self.expiry_threshold = 10.days
|
15
|
+
self.clean_job_cron = "0 0 * * *"
|
15
16
|
|
16
17
|
def self.configure
|
17
18
|
yield self
|
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.
|
4
|
+
version: 0.6.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: 2016-05-
|
13
|
+
date: 2016-05-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -280,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
280
280
|
version: '0'
|
281
281
|
requirements: []
|
282
282
|
rubyforge_project:
|
283
|
-
rubygems_version: 2.
|
283
|
+
rubygems_version: 2.5.1
|
284
284
|
signing_key:
|
285
285
|
specification_version: 4
|
286
286
|
summary: Asynchronous API communication
|