zenaton 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -2
- data/Gemfile.lock +6 -6
- data/README.md +124 -96
- data/lib/zenaton/client.rb +4 -2
- data/lib/zenaton/services/properties.rb +19 -5
- data/lib/zenaton/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e51aae796ecf047bcbc9c4b3b4e4fd971191a1ebee24075b9576df8248c9c3a
|
4
|
+
data.tar.gz: a53ce602e5edeab270bebb30b11d108c568c35e1994002376989d1e9a1ce1f3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51cef86daef5b85dd46fbc4d98305d58ad277b4ee36360266a66268ecc86a9ec1fd5d3bc1ec0c0e1702af33c1f2998471f80828f52d9e88f5425512d2767d4f5
|
7
|
+
data.tar.gz: 73230ed0fa51c178553ed28a39d24f21841b2f825d558453733de02c71a871a7ca29bfb65bd734f7d0f9db71f4e6035f24f5253bd5eec51f7dfdbd951e0e22a4
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [Unreleased]
|
8
|
+
### Changes
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
## [0.4.1] - 2019-06-04
|
13
|
+
### Changes
|
14
|
+
- Fix symbol json encoding breaking compatibility with some gems
|
15
|
+
|
16
|
+
### Added
|
17
|
+
- Added `event_data` property when sending event
|
18
|
+
|
7
19
|
## [0.4.0] - 2019-03-25
|
8
20
|
### Added
|
9
21
|
- Calling `#dispatch` on tasks now allows to process tasks asynchronously
|
@@ -73,8 +85,9 @@ available.
|
|
73
85
|
### Added
|
74
86
|
- Initial release.
|
75
87
|
|
76
|
-
[Unreleased]: https://github.com/zenaton/zenaton-ruby/compare/v0.4.
|
77
|
-
[0.
|
88
|
+
[Unreleased]: https://github.com/zenaton/zenaton-ruby/compare/v0.4.1...HEAD
|
89
|
+
[0.4.1]: https://github.com/zenaton/zenaton-ruby/compare/v0.4.0...v0.4.1
|
90
|
+
[0.4.0]: https://github.com/zenaton/zenaton-ruby/compare/v0.3.1...v0.4.0
|
78
91
|
[0.3.1]: https://github.com/zenaton/zenaton-ruby/compare/v0.3.0...v0.3.1
|
79
92
|
[0.3.0]: https://github.com/zenaton/zenaton-ruby/compare/v0.2.3...v0.3.0
|
80
93
|
[0.2.3]: https://github.com/zenaton/zenaton-ruby/compare/v0.2.2...v0.2.3
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
zenaton (0.4.
|
4
|
+
zenaton (0.4.1)
|
5
5
|
activesupport
|
6
6
|
tzinfo-data
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (5.2.
|
11
|
+
activesupport (5.2.3)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
13
|
i18n (>= 0.7, < 2)
|
14
14
|
minitest (~> 5.1)
|
@@ -17,13 +17,13 @@ GEM
|
|
17
17
|
public_suffix (>= 2.0.2, < 4.0)
|
18
18
|
ast (2.4.0)
|
19
19
|
coderay (1.1.2)
|
20
|
-
concurrent-ruby (1.
|
20
|
+
concurrent-ruby (1.1.5)
|
21
21
|
crack (0.4.3)
|
22
22
|
safe_yaml (~> 1.0.0)
|
23
23
|
diff-lcs (1.3)
|
24
24
|
docile (1.3.1)
|
25
25
|
hashdiff (0.3.7)
|
26
|
-
i18n (1.
|
26
|
+
i18n (1.6.0)
|
27
27
|
concurrent-ruby (~> 1.0)
|
28
28
|
jaro_winkler (1.5.1)
|
29
29
|
json (2.1.0)
|
@@ -73,7 +73,7 @@ GEM
|
|
73
73
|
timecop (0.9.1)
|
74
74
|
tzinfo (1.2.5)
|
75
75
|
thread_safe (~> 0.1)
|
76
|
-
tzinfo-data (1.
|
76
|
+
tzinfo-data (1.2019.1)
|
77
77
|
tzinfo (>= 1.0.0)
|
78
78
|
unicode-display_width (1.4.0)
|
79
79
|
vcr (4.0.0)
|
@@ -99,4 +99,4 @@ DEPENDENCIES
|
|
99
99
|
zenaton!
|
100
100
|
|
101
101
|
BUNDLED WITH
|
102
|
-
1.
|
102
|
+
1.17.2
|
data/README.md
CHANGED
@@ -1,19 +1,58 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
<p align="center">
|
2
|
+
<img src="https://user-images.githubusercontent.com/36400935/58254828-e5176880-7d6b-11e9-9094-3f46d91faeee.png" /><br>
|
3
|
+
Easy Asynchronous Jobs Manager for Developers <br>
|
4
|
+
<a href="https://zenaton.com/documentation/ruby/getting-started/">
|
5
|
+
<strong> Explore the docs » </strong>
|
6
|
+
</a> <br>
|
7
|
+
<a href="https://zenaton.com"> Website </a>
|
8
|
+
·
|
9
|
+
<a href="https://github.com/zenaton/examples-ruby"> Examples in Ruby </a>
|
10
|
+
·
|
11
|
+
<a href="https://app.zenaton.com/tutorial/ruby"> Tutorial in Ruby </a>
|
12
|
+
|
13
|
+
<p align="center">
|
14
|
+
<a href="https://rubygems.org/gems/zenaton"><img src="https://img.shields.io/gem/v/zenaton.svg" alt="Gem Version"></a>
|
15
|
+
<a href="https://circleci.com/gh/zenaton/zenaton-ruby/tree/master" rel="nofollow" target="_blank"><img src="https://img.shields.io/circleci/project/github/zenaton/zenaton-ruby/master.svg" alt="CircleCI" style="max-width:100%;"></a>
|
16
|
+
<a href="/LICENSE" target="_blank"><img src="https://img.shields.io/github/license/zenaton/zenaton-ruby.svg" alt="License" style="max-width:100%;"></a>
|
17
|
+
</p>
|
18
|
+
</p>
|
19
|
+
|
20
|
+
<details>
|
21
|
+
<summary><strong>Table of contents</strong></summary>
|
22
|
+
|
23
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
24
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
25
|
+
|
26
|
+
- [Getting Started](#getting-started)
|
27
|
+
- [Requirements](#requirements)
|
28
|
+
- [Installation](#installation)
|
29
|
+
- [Setup with Ruby on Rails](#setup-with-ruby-on-rails)
|
30
|
+
- [Client initialization](#client-initialization)
|
31
|
+
- [Worker Installation](#worker-installation)
|
32
|
+
- [Setup with plain Ruby](#setup-with-plain-ruby)
|
33
|
+
- [Client Initialization](#client-initialization)
|
34
|
+
- [Worker Installation](#worker-installation-1)
|
35
|
+
- [Usage](#usage)
|
36
|
+
- [Writing a task](#writing-a-task)
|
37
|
+
- [Writing a workflow](#writing-a-workflow)
|
38
|
+
- [Lauching a workflow](#lauching-a-workflow)
|
39
|
+
- [Documentation](#documentation)
|
40
|
+
- [Development](#development)
|
41
|
+
- [Contributing](#contributing)
|
42
|
+
- [License](#license)
|
43
|
+
- [Code of Conduct](#code-of-conduct)
|
44
|
+
|
45
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
46
|
+
|
47
|
+
</details>
|
48
|
+
|
49
|
+
## Getting Started
|
50
|
+
|
51
|
+
### Requirements
|
13
52
|
|
14
53
|
This gem has been tested with Ruby 2.3 and later.
|
15
54
|
|
16
|
-
|
55
|
+
### Installation
|
17
56
|
|
18
57
|
Add this line to your application's Gemfile:
|
19
58
|
|
@@ -29,58 +68,38 @@ Or install it yourself as:
|
|
29
68
|
|
30
69
|
$ gem install zenaton
|
31
70
|
|
32
|
-
##
|
71
|
+
## Setup with Ruby on Rails
|
33
72
|
|
34
|
-
|
35
|
-
|
36
|
-
### Client Initialization
|
73
|
+
### Client initialization
|
37
74
|
|
38
|
-
|
75
|
+
1. Create an initializer in `config/initializers/zenaton.rb` with the following:
|
39
76
|
|
40
|
-
Then you can initialize your Zenaton client:
|
41
77
|
```ruby
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
app_env = ENV['ZENATON_APP_ENV']
|
48
|
-
|
49
|
-
Zenaton::Client.init(app_id, api_token, app_env)
|
78
|
+
Zenaton::Client.init(
|
79
|
+
ENV['ZENATON_APP_ID'],
|
80
|
+
ENV['ZENATON_API_TOKEN'],
|
81
|
+
ENV['ZENATON_APP_ENV']
|
82
|
+
)
|
50
83
|
```
|
51
84
|
|
52
|
-
|
53
|
-
|
54
|
-
Writing a workflow is as simple as:
|
85
|
+
2. Add a `.env` file at the root of your project with [your credentials](https://app.zenaton.com/api):
|
55
86
|
|
56
|
-
```ruby
|
57
|
-
class MyWorkflow < Zenaton::Interfaces::Worflow
|
58
|
-
include Zenatonable
|
59
|
-
|
60
|
-
def handle
|
61
|
-
# Your workflow implementation
|
62
|
-
end
|
63
|
-
end
|
64
87
|
```
|
65
|
-
|
88
|
+
ZENATON_API_URL=...
|
89
|
+
ZENATON_APP_ID=...
|
90
|
+
ZENATON_API_TOKEN=...
|
91
|
+
```
|
66
92
|
|
67
|
-
|
68
|
-
```ruby
|
69
|
-
class MyTask < Zenaton::Interfaces::Task
|
70
|
-
include Zenatonable
|
93
|
+
Don't forget to add it to your `.gitignore`:
|
71
94
|
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
end
|
95
|
+
```bash
|
96
|
+
$ echo ".env" >> .gitignore
|
76
97
|
```
|
77
98
|
|
78
|
-
|
79
|
-
|
80
|
-
Once your Zenaton client is initialized, you can start a workflow with
|
99
|
+
3. Add the [dotenv gem](https://github.com/bkeepers/dotenv) to your `Gemfile` to easily load these variables in development:
|
81
100
|
|
82
101
|
```ruby
|
83
|
-
|
102
|
+
gem 'dotenv-rails', groups: [:development, :test]
|
84
103
|
```
|
85
104
|
|
86
105
|
### Worker Installation
|
@@ -89,54 +108,58 @@ Your workflow's tasks will be executed on your worker servers. Please install a
|
|
89
108
|
|
90
109
|
$ curl https://install.zenaton.com | sh
|
91
110
|
|
92
|
-
that you can start and configure with
|
111
|
+
that you can start and configure from your application directory with
|
93
112
|
|
94
|
-
$ zenaton start && zenaton listen --env=.env --
|
113
|
+
$ zenaton start && zenaton listen --env=.env --rails
|
95
114
|
|
96
|
-
where `.env` is the env file containing your credentials
|
115
|
+
where `.env` is the env file containing [your credentials](https://app.zenaton.com/api).
|
97
116
|
|
98
|
-
|
117
|
+
**Note** In this example we created our workflows and tasks in the `/app`
|
118
|
+
folder since Rails will autoload ruby files in that path. If you create your
|
119
|
+
workflows and tasks somewhere else, ensure Rails loads them at boot time.
|
99
120
|
|
100
|
-
|
121
|
+
Your are now ready to [write tasks and workflows](#usage) !
|
101
122
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
zenaton
|
107
|
-
|
108
|
-
|
109
|
-
```
|
123
|
+
## Setup with plain Ruby
|
124
|
+
|
125
|
+
### Client Initialization
|
126
|
+
|
127
|
+
You will need to export three environment variables: `ZENATON_APP_ID`, `ZENATON_API_TOKEN`, `ZENATON_APP_ENV`. You'll find them [here](https://app.zenaton.com/api).
|
128
|
+
|
129
|
+
Then you can initialize your Zenaton client:
|
110
130
|
|
111
|
-
Then create an initializer in `config/initializers/zenaton.rb` with the
|
112
|
-
following:
|
113
131
|
```ruby
|
132
|
+
require 'dotenv/load'
|
133
|
+
require 'zenaton'
|
134
|
+
|
114
135
|
Zenaton::Client.init(
|
115
|
-
|
116
|
-
|
117
|
-
|
136
|
+
ENV['ZENATON_APP_ID'],
|
137
|
+
ENV['ZENATON_API_TOKEN'],
|
138
|
+
ENV['ZENATON_APP_ENV']
|
118
139
|
)
|
119
140
|
```
|
120
141
|
|
121
|
-
###
|
142
|
+
### Worker Installation
|
122
143
|
|
123
|
-
|
144
|
+
Your workflow's tasks will be executed on your worker servers. Please install a Zenaton worker on it:
|
124
145
|
|
125
|
-
|
126
|
-
class MyWorkflow < Zenaton::Interfaces::Worflow
|
127
|
-
include Zenatonable
|
146
|
+
$ curl https://install.zenaton.com | sh
|
128
147
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
148
|
+
that you can start and configure with
|
149
|
+
|
150
|
+
$ zenaton start && zenaton listen --env=.env --boot=boot.rb
|
151
|
+
|
152
|
+
where `.env` is the env file containing [your credentials](https://app.zenaton.com/api), and `boot.rb` is a file that will be included before each task execution - this file should load all workflow classes.
|
153
|
+
|
154
|
+
## Usage
|
155
|
+
|
156
|
+
For more detailed examples, please check [Zenaton Ruby examples](https://github.com/zenaton/examples-ruby).
|
157
|
+
|
158
|
+
### Writing a task
|
135
159
|
|
136
|
-
And we can create a task in `app/tasks/my_task.rb`.
|
137
160
|
```ruby
|
138
161
|
class MyTask < Zenaton::Interfaces::Task
|
139
|
-
include Zenatonable
|
162
|
+
include Zenaton::Traits::Zenatonable
|
140
163
|
|
141
164
|
def handle
|
142
165
|
# Your task implementation
|
@@ -144,32 +167,37 @@ class MyTask < Zenaton::Interfaces::Task
|
|
144
167
|
end
|
145
168
|
```
|
146
169
|
|
147
|
-
|
170
|
+
[Check the documentation for more details.](https://zenaton.com/documentation/ruby/tasks)
|
171
|
+
|
172
|
+
### Writing a workflow
|
148
173
|
|
149
|
-
We can start a workflow from anywhere in our application code with:
|
150
174
|
```ruby
|
151
|
-
MyWorkflow
|
175
|
+
class MyWorkflow < Zenaton::Interfaces::Workflow
|
176
|
+
include Zenaton::Traits::Zenatonable
|
177
|
+
|
178
|
+
def handle
|
179
|
+
# Your workflow implementation
|
180
|
+
end
|
181
|
+
end
|
152
182
|
```
|
153
183
|
|
154
|
-
|
184
|
+
Note that your workflow implementation should be idempotent.
|
155
185
|
|
156
|
-
|
186
|
+
With Ruby on Rails, you may need to run `$ spring stop` to force Spring to load your app fresh.
|
157
187
|
|
158
|
-
|
188
|
+
[Check the documentation for more details.](https://zenaton.com/documentation/ruby/workflow-basics)
|
159
189
|
|
160
|
-
|
161
|
-
|
162
|
-
$ zenaton start && zenaton listen --env=.env --rails
|
190
|
+
### Lauching a workflow
|
163
191
|
|
164
|
-
|
192
|
+
We can start a workflow from anywhere in our application code with:
|
165
193
|
|
166
|
-
|
167
|
-
|
168
|
-
|
194
|
+
```ruby
|
195
|
+
MyWorkflow.new.dispatch
|
196
|
+
```
|
169
197
|
|
170
198
|
## Documentation
|
171
199
|
|
172
|
-
Please see https://zenaton.com/documentation for complete documentation.
|
200
|
+
Please see https://zenaton.com/documentation/ruby/getting-started for complete documentation.
|
173
201
|
|
174
202
|
## Development
|
175
203
|
|
data/lib/zenaton/client.rb
CHANGED
@@ -33,8 +33,9 @@ module Zenaton
|
|
33
33
|
|
34
34
|
PROG = 'Ruby' # The current programming language
|
35
35
|
|
36
|
-
EVENT_INPUT = 'event_input' # Parameter name for event
|
36
|
+
EVENT_INPUT = 'event_input' # Parameter name for event input
|
37
37
|
EVENT_NAME = 'event_name' # Parameter name for event name
|
38
|
+
EVENT_DATA = 'event_data' # Parameter name for event data
|
38
39
|
|
39
40
|
WORKFLOW_KILL = 'kill' # Worker update mode to stop a worker
|
40
41
|
WORKFLOW_PAUSE = 'pause' # Worker udpate mode to pause a worker
|
@@ -174,7 +175,8 @@ module Zenaton
|
|
174
175
|
ATTR_NAME => workflow_name,
|
175
176
|
ATTR_ID => custom_id,
|
176
177
|
EVENT_NAME => event.class.name,
|
177
|
-
EVENT_INPUT => @serializer.encode(@properties.from(event))
|
178
|
+
EVENT_INPUT => @serializer.encode(@properties.from(event)),
|
179
|
+
EVENT_DATA => @serializer.encode(event)
|
178
180
|
}
|
179
181
|
@http.post(send_event_url, body)
|
180
182
|
end
|
@@ -1,7 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'singleton'
|
4
|
-
require 'json/add/
|
4
|
+
require 'json/add/date'
|
5
|
+
require 'json/add/date_time'
|
6
|
+
require 'json/add/exception'
|
7
|
+
require 'json/add/range'
|
8
|
+
require 'json/add/regexp'
|
9
|
+
require 'json/add/struct'
|
10
|
+
require 'json/add/time'
|
5
11
|
require 'json/add/rational'
|
6
12
|
require 'json/add/complex'
|
7
13
|
require 'json/add/bigdecimal'
|
@@ -97,14 +103,22 @@ module Zenaton
|
|
97
103
|
end
|
98
104
|
|
99
105
|
def from_complex_type(object)
|
100
|
-
|
101
|
-
|
106
|
+
if object.is_a?(Symbol)
|
107
|
+
{ 's' => object.to_s }
|
108
|
+
else
|
109
|
+
JSON.parse(object.to_json).tap do |attributes|
|
110
|
+
attributes.delete('json_class')
|
111
|
+
end
|
102
112
|
end
|
103
113
|
end
|
104
114
|
|
105
115
|
def set_complex_type(object, props)
|
106
|
-
|
107
|
-
|
116
|
+
if object.is_a?(Symbol)
|
117
|
+
props['s'].to_sym
|
118
|
+
else
|
119
|
+
props['json_class'] = object.class.name
|
120
|
+
JSON(props.to_json)
|
121
|
+
end
|
108
122
|
end
|
109
123
|
|
110
124
|
def special_case?(object)
|
data/lib/zenaton/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zenaton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zenaton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|