zenaton 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -0
- data/CHANGELOG.md +17 -2
- data/Gemfile.lock +1 -1
- data/README.md +4 -2
- data/lib/zenaton/client.rb +57 -12
- data/lib/zenaton/engine.rb +1 -1
- data/lib/zenaton/traits/with_timestamp.rb +30 -5
- data/lib/zenaton/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a28c9df01efe5b8a7a242e2d25b12ea713b33895104fc28b61e0359c25a38f60
|
4
|
+
data.tar.gz: a06c860ed8c3c049ab31005369ac84d37d3fe24f3d2cc7501cd4b6314bcfc591
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15be902a6bcaf15248c3374eb86439f05a59acb0788cadfe05347bbc159925a2cf73596a9d8cd3519e77961789a888ba46cb66df19f69a60a1325999ac531af8
|
7
|
+
data.tar.gz: 8a1f6f4f34b040a7c10c5b2f52d8999389b0cde4b0c100ece7784e9e13c8443e173c90616a66cce1c1431afe1a86b6f36d533c01f8219f688d67edc199cfb44e
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,21 @@ 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
|
-
## [
|
7
|
+
## [0.4.0] - 2019-03-25
|
8
|
+
### Added
|
9
|
+
- Calling `#dispatch` on tasks now allows to process tasks asynchronously
|
10
|
+
|
11
|
+
### Changes
|
12
|
+
- Update Zenaton engine URL to point to the new subdomain.
|
13
|
+
|
14
|
+
### Fixed
|
15
|
+
- When creating a `Wait` task which uses both `#at` (to specify time) and either
|
16
|
+
`#day_of_month` or `#monday` et al (to set day), it was surprising that the
|
17
|
+
wait task only waited for next week/month when it would make sense to wait for
|
18
|
+
later the same day. For example, on a Monday at 1 p.m, it waits for a couple
|
19
|
+
of hours if you create a wait task with `.monday(1).at("15")`. Otherwise the
|
20
|
+
previous behaviour of waiting for next week is preserved.
|
21
|
+
- Fix encoding of query parameters when searching for existing workflows
|
8
22
|
|
9
23
|
## [0.3.1] - 2018-10-02
|
10
24
|
### Fixed
|
@@ -59,7 +73,8 @@ available.
|
|
59
73
|
### Added
|
60
74
|
- Initial release.
|
61
75
|
|
62
|
-
[Unreleased]: https://github.com/zenaton/zenaton-ruby/compare/v0.
|
76
|
+
[Unreleased]: https://github.com/zenaton/zenaton-ruby/compare/v0.4.0...HEAD
|
77
|
+
[0.3.1]: https://github.com/zenaton/zenaton-ruby/compare/v0.3.1...v0.4.0
|
63
78
|
[0.3.1]: https://github.com/zenaton/zenaton-ruby/compare/v0.3.0...v0.3.1
|
64
79
|
[0.3.0]: https://github.com/zenaton/zenaton-ruby/compare/v0.2.3...v0.3.0
|
65
80
|
[0.2.3]: https://github.com/zenaton/zenaton-ruby/compare/v0.2.2...v0.2.3
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Zenaton library for Ruby
|
2
|
-
[![Gem Version](https://
|
3
|
-
[![
|
2
|
+
[![Gem Version](https://img.shields.io/gem/v/zenaton.svg)](https://rubygems.org/gems/zenaton)
|
3
|
+
[![Gem Downloads](https://img.shields.io/gem/dt/zenaton.svg)](https://rubygems.org/gems/zenaton)
|
4
|
+
[![CircleCI](https://img.shields.io/circleci/project/github/zenaton/zenaton-ruby/master.svg)](https://circleci.com/gh/zenaton/zenaton-ruby/tree/master)
|
5
|
+
[![License](https://img.shields.io/github/license/zenaton/zenaton-ruby.svg)](LICENSE.txt)
|
4
6
|
|
5
7
|
This Zenaton library for Ruby lets you code and launch workflows using Zenaton platform. You can sign up for an account at [https://zenaton/com](http://zenaton.com)
|
6
8
|
|
data/lib/zenaton/client.rb
CHANGED
@@ -11,7 +11,7 @@ module Zenaton
|
|
11
11
|
class Client
|
12
12
|
include Singleton
|
13
13
|
|
14
|
-
ZENATON_API_URL = 'https://zenaton.com/
|
14
|
+
ZENATON_API_URL = 'https://api.zenaton.com/v1' # Zenaton api url
|
15
15
|
ZENATON_WORKER_URL = 'http://localhost' # Default worker url
|
16
16
|
DEFAULT_WORKER_PORT = 4001 # Default worker port
|
17
17
|
WORKER_API_VERSION = 'v_newton' # Default worker api version
|
@@ -28,6 +28,8 @@ module Zenaton
|
|
28
28
|
ATTR_DATA = 'data' # Parameter name for json payload
|
29
29
|
ATTR_PROG = 'programming_language' # Parameter name for the language
|
30
30
|
ATTR_MODE = 'mode' # Parameter name for the worker update mode
|
31
|
+
# Parameter name for task maximum processing time
|
32
|
+
ATTR_MAX_PROCESSING_TIME = 'maxProcessingTime'
|
31
33
|
|
32
34
|
PROG = 'Ruby' # The current programming language
|
33
35
|
|
@@ -62,23 +64,49 @@ module Zenaton
|
|
62
64
|
|
63
65
|
# Gets the url for the workers
|
64
66
|
# @param resource [String] the endpoint for the worker
|
65
|
-
# @param params [String]
|
67
|
+
# @param params [Hash|String] query params to be url encoded
|
66
68
|
# @return [String] the workers url with parameters
|
67
|
-
def worker_url(resource = '', params =
|
69
|
+
def worker_url(resource = '', params = {})
|
68
70
|
base_url = ENV['ZENATON_WORKER_URL'] || ZENATON_WORKER_URL
|
69
71
|
port = ENV['ZENATON_WORKER_PORT'] || DEFAULT_WORKER_PORT
|
70
|
-
url = "#{base_url}:#{port}/api/#{WORKER_API_VERSION}/#{resource}
|
71
|
-
|
72
|
+
url = "#{base_url}:#{port}/api/#{WORKER_API_VERSION}/#{resource}"
|
73
|
+
|
74
|
+
if params.is_a?(Hash)
|
75
|
+
append_params_to_url(url, params)
|
76
|
+
else
|
77
|
+
add_app_env("#{url}?", params)
|
78
|
+
end
|
72
79
|
end
|
73
80
|
|
74
81
|
# Gets the url for zenaton api
|
75
82
|
# @param resource [String] the endpoint for the api
|
76
|
-
# @param params [String]
|
83
|
+
# @param params [Hash|String] query params to be url encoded
|
77
84
|
# @return [String] the api url with parameters
|
78
|
-
def website_url(resource = '', params =
|
85
|
+
def website_url(resource = '', params = {})
|
79
86
|
api_url = ENV['ZENATON_API_URL'] || ZENATON_API_URL
|
80
|
-
url = "#{api_url}/#{resource}
|
81
|
-
|
87
|
+
url = "#{api_url}/#{resource}"
|
88
|
+
|
89
|
+
if params.is_a?(Hash)
|
90
|
+
params[API_TOKEN] = @api_token
|
91
|
+
append_params_to_url(url, params)
|
92
|
+
else
|
93
|
+
add_app_env("#{url}?#{API_TOKEN}=#{@api_token}&", params)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Start a single task
|
98
|
+
# @param task [Zenaton::Interfaces::Task]
|
99
|
+
def start_task(task)
|
100
|
+
max_processing_time = if task.respond_to?(:max_processing_time)
|
101
|
+
task.max_processing_time
|
102
|
+
end
|
103
|
+
@http.post(
|
104
|
+
worker_url('tasks'),
|
105
|
+
ATTR_PROG => PROG,
|
106
|
+
ATTR_NAME => class_name(task),
|
107
|
+
ATTR_DATA => @serializer.encode(@properties.from(task)),
|
108
|
+
ATTR_MAX_PROCESSING_TIME => max_processing_time
|
109
|
+
)
|
82
110
|
end
|
83
111
|
|
84
112
|
# Start the specified workflow
|
@@ -123,7 +151,8 @@ module Zenaton
|
|
123
151
|
# @param custom_id [String] the custom ID of the workflow
|
124
152
|
# @return [Zenaton::Interfaces::Workflow, nil]
|
125
153
|
def find_workflow(workflow_name, custom_id)
|
126
|
-
params =
|
154
|
+
params = { ATTR_ID => custom_id, ATTR_NAME => workflow_name }
|
155
|
+
params[ATTR_PROG] = PROG
|
127
156
|
data = @http.get(instance_website_url(params))['data']
|
128
157
|
data && @properties.object_from(
|
129
158
|
data['name'],
|
@@ -152,18 +181,34 @@ module Zenaton
|
|
152
181
|
|
153
182
|
private
|
154
183
|
|
184
|
+
# DEPRECATED: This implementation does not safely encode the parameters to
|
185
|
+
# be passed as query params in a get request. This method gets called by
|
186
|
+
# agents up to version 0.4.5
|
155
187
|
def add_app_env(url, params)
|
188
|
+
deprecation_warning = <<~WARN
|
189
|
+
[WARNING] You are running a Zenaton agent with a version <= 0.4.5
|
190
|
+
Please consider upgrading to a more recent version.
|
191
|
+
WARN
|
192
|
+
warn(deprecation_warning)
|
193
|
+
|
156
194
|
app_env = @app_env ? "#{APP_ENV}=#{@app_env}&" : ''
|
157
195
|
app_id = @app_id ? "#{APP_ID}=#{@app_id}&" : ''
|
158
196
|
|
159
197
|
"#{url}#{app_env}#{app_id}#{params}"
|
160
198
|
end
|
161
199
|
|
200
|
+
def append_params_to_url(url, params)
|
201
|
+
params[APP_ENV] = @app_env if @app_env
|
202
|
+
params[APP_ID] = @app_id if @app_id
|
203
|
+
|
204
|
+
"#{url}?#{URI.encode_www_form(params)}"
|
205
|
+
end
|
206
|
+
|
162
207
|
def instance_website_url(params)
|
163
208
|
website_url('instances', params)
|
164
209
|
end
|
165
210
|
|
166
|
-
def instance_worker_url(params =
|
211
|
+
def instance_worker_url(params = {})
|
167
212
|
worker_url('instances', params)
|
168
213
|
end
|
169
214
|
|
@@ -199,7 +244,7 @@ module Zenaton
|
|
199
244
|
end
|
200
245
|
|
201
246
|
def update_instance(workflow_name, custom_id, mode)
|
202
|
-
params =
|
247
|
+
params = { ATTR_ID => custom_id }
|
203
248
|
url = instance_worker_url(params)
|
204
249
|
options = {
|
205
250
|
ATTR_PROG => PROG,
|
data/lib/zenaton/engine.rb
CHANGED
@@ -27,12 +27,14 @@ module Zenaton
|
|
27
27
|
# @return Array<Integer, NilClass>
|
28
28
|
def _get_timestamp_or_duration
|
29
29
|
return [nil, nil] unless @buffer
|
30
|
+
|
30
31
|
now, now_dup = _init_now_then
|
31
32
|
@_mode = nil
|
32
33
|
@buffer.each do |time_unit, time_value|
|
33
34
|
now_dup = _apply(time_unit, time_value, now, now_dup)
|
34
35
|
end
|
35
36
|
return [nil, diff_in_seconds(now, now_dup)] if @_mode.nil?
|
37
|
+
|
36
38
|
[now_dup.to_i, nil]
|
37
39
|
end
|
38
40
|
|
@@ -51,7 +53,7 @@ module Zenaton
|
|
51
53
|
# rubocop:disable Metrics/MethodLength
|
52
54
|
def _apply(method, value, now, now_dup)
|
53
55
|
if WEEKDAYS.include?(method)
|
54
|
-
_weekday(value, method, now_dup)
|
56
|
+
_weekday(value, method, now, now_dup)
|
55
57
|
elsif method == :timestamp
|
56
58
|
_timestamp(value)
|
57
59
|
elsif method == :at
|
@@ -64,8 +66,9 @@ module Zenaton
|
|
64
66
|
end
|
65
67
|
# rubocop:enable Metrics/MethodLength
|
66
68
|
|
67
|
-
def _weekday(value, day, now_dup)
|
69
|
+
def _weekday(value, day, now, now_dup)
|
68
70
|
_set_mode(MODE_WEEK_DAY)
|
71
|
+
value -= 1 if later_today?(now, day)
|
69
72
|
value.times { |_n| now_dup = now_dup.next_occurring(day) }
|
70
73
|
now_dup
|
71
74
|
end
|
@@ -77,8 +80,7 @@ module Zenaton
|
|
77
80
|
|
78
81
|
def _at(time, now, now_dup)
|
79
82
|
_set_mode(MODE_AT)
|
80
|
-
|
81
|
-
now_dup = now_dup.change(hour: hour, min: min, sec: sec || 0)
|
83
|
+
now_dup = set_time_from_string(now_dup, time)
|
82
84
|
now_dup += delay if now > now_dup
|
83
85
|
now_dup
|
84
86
|
end
|
@@ -99,7 +101,7 @@ module Zenaton
|
|
99
101
|
def _day_of_month(day, now, now_dup)
|
100
102
|
_set_mode(MODE_MONTH_DAY)
|
101
103
|
now_dup = now_dup.change(day: day)
|
102
|
-
now_dup += 1.month if now
|
104
|
+
now_dup += 1.month if now >= now_dup && !later_today?(now, day)
|
103
105
|
now_dup
|
104
106
|
end
|
105
107
|
|
@@ -107,6 +109,7 @@ module Zenaton
|
|
107
109
|
error = 'Incompatible definition in Wait methods'
|
108
110
|
raise ExternalError, error if mode == @_mode
|
109
111
|
raise ExternalError, error if timestamp_mode_set?(mode)
|
112
|
+
|
110
113
|
@_mode = mode if @_mode.nil? || @_mode == MODE_AT
|
111
114
|
end
|
112
115
|
|
@@ -114,10 +117,32 @@ module Zenaton
|
|
114
117
|
(!@_mode.nil? && MODE_TIMESTAMP == mode) || (@_mode == MODE_TIMESTAMP)
|
115
118
|
end
|
116
119
|
|
120
|
+
def later_today?(now, day)
|
121
|
+
today?(now, day) && later?(now)
|
122
|
+
end
|
123
|
+
|
124
|
+
def today?(now, day)
|
125
|
+
wday = WEEKDAYS[now.wday - 1]
|
126
|
+
now.mday == day || wday == day
|
127
|
+
end
|
128
|
+
|
129
|
+
def later?(now)
|
130
|
+
time = @buffer[:at]
|
131
|
+
return false unless time
|
132
|
+
|
133
|
+
now < set_time_from_string(now.dup, time)
|
134
|
+
end
|
135
|
+
|
136
|
+
def set_time_from_string(now, string_time)
|
137
|
+
hour, min, sec = string_time.split(':').map(&:to_i)
|
138
|
+
now.change(hour: hour, min: min, sec: sec || 0)
|
139
|
+
end
|
140
|
+
|
117
141
|
class_methods do
|
118
142
|
def timezone=(timezone)
|
119
143
|
error = 'Unknown timezone'
|
120
144
|
raise ExternalError, error unless valid_timezone?(timezone)
|
145
|
+
|
121
146
|
@@_timezone = timezone
|
122
147
|
end
|
123
148
|
|
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
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zenaton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -239,8 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
239
239
|
- !ruby/object:Gem::Version
|
240
240
|
version: '0'
|
241
241
|
requirements: []
|
242
|
-
|
243
|
-
rubygems_version: 2.7.6
|
242
|
+
rubygems_version: 3.0.3
|
244
243
|
signing_key:
|
245
244
|
specification_version: 4
|
246
245
|
summary: Zenaton ruby library
|