zenaton 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +79 -52
  3. data/.gitignore +7 -0
  4. data/.rubocop.yml +4 -0
  5. data/Appraisals +13 -0
  6. data/CHANGELOG.md +17 -1
  7. data/Gemfile.lock +17 -8
  8. data/gemfiles/.bundle/config +2 -0
  9. data/gemfiles/rails_5.0.gemfile +7 -0
  10. data/gemfiles/rails_5.1.gemfile +7 -0
  11. data/gemfiles/rails_5.2.gemfile +7 -0
  12. data/lib/zenaton/client.rb +63 -0
  13. data/lib/zenaton/contexts.rb +7 -0
  14. data/lib/zenaton/contexts/task.rb +33 -0
  15. data/lib/zenaton/contexts/workflow.rb +17 -0
  16. data/lib/zenaton/engine.rb +16 -0
  17. data/lib/zenaton/interfaces/task.rb +30 -1
  18. data/lib/zenaton/interfaces/workflow.rb +15 -0
  19. data/lib/zenaton/refinements.rb +16 -0
  20. data/lib/zenaton/refinements/big_decimal.rb +25 -0
  21. data/lib/zenaton/refinements/class.rb +21 -0
  22. data/lib/zenaton/refinements/complex.rb +22 -0
  23. data/lib/zenaton/refinements/date.rb +26 -0
  24. data/lib/zenaton/refinements/date_time.rb +40 -0
  25. data/lib/zenaton/refinements/exception.rb +24 -0
  26. data/lib/zenaton/refinements/object.rb +15 -0
  27. data/lib/zenaton/refinements/open_struct.rb +26 -0
  28. data/lib/zenaton/refinements/range.rb +21 -0
  29. data/lib/zenaton/refinements/rational.rb +22 -0
  30. data/lib/zenaton/refinements/regexp.rb +22 -0
  31. data/lib/zenaton/refinements/struct.rb +24 -0
  32. data/lib/zenaton/refinements/symbol.rb +21 -0
  33. data/lib/zenaton/refinements/time.rb +32 -0
  34. data/lib/zenaton/services/graphql.rb +71 -0
  35. data/lib/zenaton/services/http.rb +14 -9
  36. data/lib/zenaton/services/properties.rb +11 -57
  37. data/lib/zenaton/services/serializer.rb +2 -0
  38. data/lib/zenaton/traits/with_timestamp.rb +4 -2
  39. data/lib/zenaton/traits/zenatonable.rb +9 -0
  40. data/lib/zenaton/version.rb +1 -1
  41. data/zenaton.gemspec +2 -0
  42. metadata +54 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5193a41e1e744fd9b64001ab65fdbfaa793780dddd9ba18a4e6fa4265a3ae6c7
4
- data.tar.gz: 45c818b476ba46ffb22023015b10555a60f91528ef2d8e51770d429663213f0e
3
+ metadata.gz: 987a8312a73e5b97d12089a115fcfa4cb15876c019dbc671377ea1a8129e024f
4
+ data.tar.gz: 9cff61f323b485d832b95d00e3c4d90874966690f334a9f652c3fa41c749b24d
5
5
  SHA512:
6
- metadata.gz: bddc36983a08704fab6c903c40dc6edd8691f593e7eedca72078be15ce77d25b571fbd1ad9d4340b2277fc7f0760ab9b959a306c89f41000f55cb3ecb2e1a17f
7
- data.tar.gz: f9019cd0975a6d8f013f7516b8df0aac07194b1bf04e3fa9ee48ca9932b94623e557796ebb2cd283393426d009a2c38434d25576b47da8c662d6e155f40fbbd4
6
+ metadata.gz: 3482971a72f81d455dd6ff780ed421dbc4f4033d7e45a2b5334ef3da2592d2a983700b6750575147169db0ca94a59d02042742391e654f45e44ddc5a1960b8be
7
+ data.tar.gz: 8eca6ac2710232efcb022421fd7f20a9ba64e97716ca2dcc819f6effca6d144403b0941e688ef96ff91d0ea30663911b7c3b223b5ea51a4a8cd237ff9d85fe22
@@ -1,69 +1,96 @@
1
- version: 2
1
+ version: 2.1
2
2
 
3
- shared: &shared
4
- working_directory: ~/repo
3
+ commands:
4
+ test:
5
+ description: Run automated tests
5
6
 
6
- steps:
7
- - checkout
7
+ steps:
8
+ - checkout
9
+ - restore_cache:
10
+ keys:
11
+ - v3-dependencies-{{ checksum "Gemfile.lock" }}
12
+ - v3-dependencies-
8
13
 
9
- - restore_cache:
10
- keys:
11
- - v1-dependencies-{{ checksum "Gemfile.lock" }}
12
- - v1-dependencies-
14
+ - run:
15
+ name: install dependencies
16
+ command: |
17
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
13
18
 
14
- - run:
15
- name: install dependencies
16
- command: |
17
- bundle install --jobs=4 --retry=3 --path vendor/bundle
19
+ - run:
20
+ name: Install Rails gemfiles
21
+ command: |
22
+ bundle exec appraisal install
18
23
 
19
- - save_cache:
20
- paths:
21
- - ./vendor/bundle
22
- key: v1-dependencies-{{ checksum "Gemfile.lock" }}
24
+ - save_cache:
25
+ paths:
26
+ - ./vendor/bundle
27
+ key: v3-dependencies-{{ checksum "Gemfile.lock" }}
23
28
 
24
- - run:
25
- name: run code linter
26
- command: |
27
- bundle exec rubocop
29
+ - run:
30
+ name: run code linter
31
+ command: |
32
+ bundle exec rubocop --config .rubocop.yml
28
33
 
29
- - run:
30
- name: run tests
31
- command: |
32
- bundle exec rake
34
+ - run:
35
+ name: run tests
36
+ command: |
37
+ bundle exec rake
33
38
 
34
- - run:
35
- name: audit dependencies for known CVEs
36
- command: |
37
- gem install bundler-audit
38
- bundle audit check --update
39
+ - run:
40
+ name: audit dependencies for known CVEs
41
+ command: |
42
+ gem install bundler-audit
43
+ bundle audit check --update
39
44
 
40
- - store_artifacts:
41
- path: ./coverage
42
- destination: coverage
45
+ - run:
46
+ name: Run tests without Rails
47
+ command: |
48
+ bundle exec appraisal rspec \
49
+ --format RspecJunitFormatter \
50
+ --out /tmp/test-results/rspec/results.xml \
51
+ --format progress
52
+
53
+ - run:
54
+ name: Run tests with Rails
55
+ command: |
56
+ bundle exec appraisal rspec \
57
+ --format RspecJunitFormatter \
58
+ --out /tmp/test-results/rspec/results.xml \
59
+ --format progress \
60
+ -r rails_helper.rb
61
+
62
+ - store_test_results:
63
+ path: /tmp/test-results
64
+ - store_artifacts:
65
+ path: ./coverage
66
+ destination: coverage
43
67
 
44
68
  jobs:
45
- "ruby-2.3":
46
- <<: *shared
47
- docker:
48
- - image: circleci/ruby:2.3
49
- "ruby-2.4":
50
- <<: *shared
51
- docker:
52
- - image: circleci/ruby:2.4
53
- "ruby-2.5":
54
- <<: *shared
55
- docker:
56
- - image: circleci/ruby:2.5
57
- "ruby-2.6":
58
- <<: *shared
69
+ run_tests:
70
+ description: Run the tests
59
71
  docker:
60
- - image: circleci/ruby:2.6
72
+ - image: "circleci/ruby:<<parameters.ruby>>"
73
+ parameters:
74
+ ruby:
75
+ description: The ruby version to use
76
+ type: enum
77
+ enum: ["2.3", "2.4", "2.5", "2.6"]
78
+ steps:
79
+ - test
61
80
 
62
81
  workflows:
63
82
  version: 2
64
83
  build:
65
84
  jobs:
66
- - "ruby-2.3"
67
- - "ruby-2.4"
68
- - "ruby-2.5"
69
- - "ruby-2.6"
85
+ - run_tests:
86
+ name: "Ruby 2.3"
87
+ ruby: "2.3"
88
+ - run_tests:
89
+ name: "Ruby 2.4"
90
+ ruby: "2.4"
91
+ - run_tests:
92
+ name: "Ruby 2.5"
93
+ ruby: "2.5"
94
+ - run_tests:
95
+ name: "Ruby 2.6"
96
+ ruby: "2.6"
data/.gitignore CHANGED
@@ -6,6 +6,13 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /vendor/
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
13
+
14
+ # appraisal lock files
15
+ /gemfiles/*.lock
16
+
17
+ # asdf ruby version file
18
+ .tool-versions
@@ -3,6 +3,10 @@ require: rubocop-rspec
3
3
  AllCops:
4
4
  TargetRubyVersion: 2.3
5
5
 
6
+ Exclude:
7
+ - 'gemfiles/**/*'
8
+ - 'vendor/bundle/**/*'
9
+
6
10
  Metrics/BlockLength:
7
11
  Enabled: true
8
12
  Exclude:
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise 'rails-5.0' do
4
+ gem 'rails', '~> 5.0.0'
5
+ end
6
+
7
+ appraise 'rails-5.1' do
8
+ gem 'rails', '~> 5.1.0'
9
+ end
10
+
11
+ appraise 'rails-5.2' do
12
+ gem 'rails', '~> 5.2.0'
13
+ end
@@ -11,6 +11,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
11
11
 
12
12
  ### Fixed
13
13
 
14
+ ## [0.5.0] - 2019-08-27
15
+ ### Changes
16
+ - No longer load JSON core extensions. Use our own refinements to avoid clashes
17
+ with frameworks and user code.
18
+
19
+ ### Added
20
+ - (De)Serialization support for instances of Class.
21
+ - Execution context for tasks and workflows
22
+ - Optional `on_error_retry_delay` method handling task failures and specifying
23
+ how many seconds to wait before retrying.
24
+ - Added scheduling tasks and workflows feature.
25
+
26
+ ### Fixed
27
+ - Backport of ActiveSupport's `next_occurring` for older versions.
28
+
14
29
  ## [0.4.2] - 2019-08-05
15
30
  ### Added
16
31
 
@@ -96,7 +111,8 @@ available.
96
111
  ### Added
97
112
  - Initial release.
98
113
 
99
- [Unreleased]: https://github.com/zenaton/zenaton-ruby/compare/v0.4.2...HEAD
114
+ [Unreleased]: https://github.com/zenaton/zenaton-ruby/compare/v0.5.0...HEAD
115
+ [0.5.0]: https://github.com/zenaton/zenaton-ruby/compare/v0.4.2...v0.5.0
100
116
  [0.4.2]: https://github.com/zenaton/zenaton-ruby/compare/v0.4.1...v0.4.2
101
117
  [0.4.1]: https://github.com/zenaton/zenaton-ruby/compare/v0.4.0...v0.4.1
102
118
  [0.4.0]: https://github.com/zenaton/zenaton-ruby/compare/v0.3.1...v0.4.0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zenaton (0.4.2)
4
+ zenaton (0.5.0)
5
5
  activesupport
6
6
  tzinfo-data
7
7
 
@@ -13,8 +13,12 @@ GEM
13
13
  i18n (>= 0.7, < 2)
14
14
  minitest (~> 5.1)
15
15
  tzinfo (~> 1.1)
16
- addressable (2.5.2)
16
+ addressable (2.6.0)
17
17
  public_suffix (>= 2.0.2, < 4.0)
18
+ appraisal (2.2.0)
19
+ bundler
20
+ rake
21
+ thor (>= 0.14.0)
18
22
  ast (2.4.0)
19
23
  coderay (1.1.2)
20
24
  concurrent-ruby (1.1.5)
@@ -22,7 +26,7 @@ GEM
22
26
  safe_yaml (~> 1.0.0)
23
27
  diff-lcs (1.3)
24
28
  docile (1.3.1)
25
- hashdiff (0.3.7)
29
+ hashdiff (1.0.0)
26
30
  i18n (1.6.0)
27
31
  concurrent-ruby (~> 1.0)
28
32
  jaro_winkler (1.5.1)
@@ -36,7 +40,7 @@ GEM
36
40
  pry (0.11.3)
37
41
  coderay (~> 1.1.0)
38
42
  method_source (~> 0.9.0)
39
- public_suffix (3.0.2)
43
+ public_suffix (3.1.1)
40
44
  rainbow (3.0.0)
41
45
  rake (10.5.0)
42
46
  rspec (3.7.0)
@@ -52,6 +56,8 @@ GEM
52
56
  diff-lcs (>= 1.2.0, < 2.0)
53
57
  rspec-support (~> 3.7.0)
54
58
  rspec-support (3.7.1)
59
+ rspec_junit_formatter (0.4.1)
60
+ rspec-core (>= 2, < 4, != 2.12.0)
55
61
  rubocop (0.58.2)
56
62
  jaro_winkler (~> 1.5.1)
57
63
  parallel (~> 1.10)
@@ -63,12 +69,13 @@ GEM
63
69
  rubocop-rspec (1.27.0)
64
70
  rubocop (>= 0.56.0)
65
71
  ruby-progressbar (1.9.0)
66
- safe_yaml (1.0.4)
72
+ safe_yaml (1.0.5)
67
73
  simplecov (0.16.1)
68
74
  docile (~> 1.1)
69
75
  json (>= 1.8, < 3)
70
76
  simplecov-html (~> 0.10.0)
71
77
  simplecov-html (0.10.2)
78
+ thor (0.20.3)
72
79
  thread_safe (0.3.6)
73
80
  timecop (0.9.1)
74
81
  tzinfo (1.2.5)
@@ -77,19 +84,21 @@ GEM
77
84
  tzinfo (>= 1.0.0)
78
85
  unicode-display_width (1.4.0)
79
86
  vcr (4.0.0)
80
- webmock (3.4.2)
87
+ webmock (3.6.2)
81
88
  addressable (>= 2.3.6)
82
89
  crack (>= 0.3.2)
83
- hashdiff
90
+ hashdiff (>= 0.4.0, < 2.0.0)
84
91
 
85
92
  PLATFORMS
86
93
  ruby
87
94
 
88
95
  DEPENDENCIES
96
+ appraisal
89
97
  bundler (~> 1.16)
90
98
  pry
91
99
  rake (~> 10.0)
92
100
  rspec (~> 3.0)
101
+ rspec_junit_formatter
93
102
  rubocop
94
103
  rubocop-rspec
95
104
  simplecov
@@ -99,4 +108,4 @@ DEPENDENCIES
99
108
  zenaton!
100
109
 
101
110
  BUNDLED WITH
102
- 1.17.2
111
+ 1.17.3
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.0.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.1.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.2.0"
6
+
7
+ gemspec path: "../"
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'securerandom'
4
4
  require 'singleton'
5
+ require 'zenaton/services/graphql'
5
6
  require 'zenaton/services/http'
6
7
  require 'zenaton/services/properties'
7
8
  require 'zenaton/services/serializer'
@@ -13,6 +14,7 @@ module Zenaton
13
14
  include Singleton
14
15
 
15
16
  ZENATON_API_URL = 'https://api.zenaton.com/v1' # Zenaton api url
17
+ ZENATON_GATEWAY_URL = 'https://gateway.zenaton.com/api' # Gateway url
16
18
  ZENATON_WORKER_URL = 'http://localhost' # Default worker url
17
19
  DEFAULT_WORKER_PORT = 4001 # Default worker port
18
20
  WORKER_API_VERSION = 'v_newton' # Default worker api version
@@ -61,6 +63,7 @@ module Zenaton
61
63
  # @private
62
64
  def initialize
63
65
  @http = Services::Http.new
66
+ @graphql = Services::GraphQL.new(http: @http)
64
67
  @serializer = Services::Serializer.new
65
68
  @properties = Services::Properties.new
66
69
  end
@@ -81,6 +84,17 @@ module Zenaton
81
84
  end
82
85
  end
83
86
 
87
+ def gateway_url
88
+ ENV['ZENATON_GATEWAY_URL'] || ZENATON_GATEWAY_URL
89
+ end
90
+
91
+ def gateway_headers
92
+ {
93
+ 'app-id' => @app_id,
94
+ 'api-token' => @api_token
95
+ }
96
+ end
97
+
84
98
  # Gets the url for zenaton api
85
99
  # @param resource [String] the endpoint for the api
86
100
  # @param params [Hash|String] query params to be url encoded
@@ -125,6 +139,55 @@ module Zenaton
125
139
  )
126
140
  end
127
141
 
142
+ def start_scheduled_task(task, cron)
143
+ res = @graphql.request(
144
+ gateway_url,
145
+ Services::GraphQL::CREATE_TASK_SCHEDULE,
146
+ create_task_schedule_input(task, cron),
147
+ gateway_headers
148
+ )
149
+ res && res['createTaskSchedule']
150
+ end
151
+
152
+ def start_scheduled_workflow(flow, cron)
153
+ res = @graphql.request(
154
+ gateway_url,
155
+ Services::GraphQL::CREATE_WORKFLOW_SCHEDULE,
156
+ create_workflow_schedule_input(flow, cron),
157
+ gateway_headers
158
+ )
159
+ res && res['createWorkflowSchedule']
160
+ end
161
+
162
+ # rubocop:disable Metrics/MethodLength
163
+ def create_workflow_schedule_input(flow, cron)
164
+ {
165
+ 'createWorkflowScheduleInput' => {
166
+ 'intentId' => SecureRandom.uuid,
167
+ 'environmentName' => @app_env,
168
+ 'cron' => cron,
169
+ 'workflowName' => class_name(flow),
170
+ 'canonicalName' => canonical_name(flow) || class_name(flow),
171
+ 'programmingLanguage' => PROG.upcase,
172
+ 'properties' => @serializer.encode(@properties.from(flow))
173
+ }
174
+ }
175
+ end
176
+ # rubocop:enable Metrics/MethodLength
177
+
178
+ def create_task_schedule_input(task, cron)
179
+ {
180
+ 'createTaskScheduleInput' => {
181
+ 'intentId' => SecureRandom.uuid,
182
+ 'environmentName' => @app_env,
183
+ 'cron' => cron,
184
+ 'taskName' => class_name(task),
185
+ 'programmingLanguage' => PROG.upcase,
186
+ 'properties' => @serializer.encode(@properties.from(task))
187
+ }
188
+ }
189
+ end
190
+
128
191
  # Stops a workflow
129
192
  # @param workflow_name [String] the class name of the workflow
130
193
  # @param custom_id [String] the custom ID of the workflow (if any)