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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64a8ce03807506f44f69762c6665bf12e84a51eb
4
- data.tar.gz: f5eca9fca67c3f7572bdea685c31e14ac7ceb2ee
3
+ metadata.gz: 2c4aa942b90ab8794c0eaeb572810d4277581df5
4
+ data.tar.gz: 186bd9cf4144c883d8f532e18caa8bd5143c2755
5
5
  SHA512:
6
- metadata.gz: 74f00f266d50fec02b36bc0445ad46e43dcefd57e0ee4d578ef1ba2691fb327ec542eac54e6b035e59599625c25edcf12ab579ffde6fbf17cd82085b96878b40
7
- data.tar.gz: db2eb606379785bb662c2ebba473afb625a16c1ce24d79f46625d07864443e338c79d432cd88a28788dbdc4b84512183c2430f5b88d9c90ba51e26a0ad42a0f6
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
- This avoids tying up your web servers executing long running processes. Scaling typically requires more workers.
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
- *Jobs that should be timed out are marked as `timed_out` approximately every minute.*
30
+ Here is a breakdown of what these parameters mean:
27
31
 
28
- Each of the `on_*` classes will get executed. For example, when the job is queued on the server, `DoOnQueue#call` will get called with the `Asyncapi::Client::Job` instance passed in. Example:
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 classes, you have access to the `job` and its fields (directly):
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 ever want the jobs to get delete, set the threshold to `nil`.
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
 
@@ -71,7 +71,6 @@ module Asyncapi::Client
71
71
  args[:time_out_at] = time_out.from_now if time_out
72
72
  job = create(args)
73
73
  JobPostWorker.perform_async(job.id, url)
74
- CleanerWorker.perform_async
75
74
  end
76
75
 
77
76
  def url
@@ -14,3 +14,11 @@ module Asyncapi
14
14
  end
15
15
  end
16
16
  end
17
+
18
+ if Sidekiq.server?
19
+ Sidekiq::Cron::Job.create({
20
+ name: "Delete old jobs",
21
+ cron: Asyncapi::Client.clean_job_cron,
22
+ klass: Asyncapi::Client::CleanerWorker.name,
23
+ })
24
+ end
@@ -9,9 +9,10 @@ require "securerandom"
9
9
  module Asyncapi
10
10
  module Client
11
11
 
12
- CONFIG_ATTRS = [:parent_controller, :expiry_threshold]
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
@@ -1,5 +1,5 @@
1
1
  module Asyncapi
2
2
  module Client
3
- VERSION = "0.5.1"
3
+ VERSION = "0.6.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.5.1
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-17 00:00:00.000000000 Z
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.2.2
283
+ rubygems_version: 2.5.1
284
284
  signing_key:
285
285
  specification_version: 4
286
286
  summary: Asynchronous API communication