marty 2.4.5 → 2.4.6

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
- SHA256:
3
- metadata.gz: 47d75b731f7458392df1acc9383452faf199aeb2f414fecf70c208f7700fae46
4
- data.tar.gz: 1d50e28afa9e48074f4c87d74ce9c23834ce995ffa3c13142bf00a19d4af51b0
2
+ SHA1:
3
+ metadata.gz: bd09d3bb234821197b1ae5dd78b70e8d07db080f
4
+ data.tar.gz: 4a2b19ce73da8012c2cd8157661e56fef22d2fd6
5
5
  SHA512:
6
- metadata.gz: d144bce2db55a1cd1023bf223839da9d5f5570b520926d06951e60a244563d4c5c2eaca8b9dd990bee4dd846895fc6cb05e4f07b92f691970f15cad7a0ff52c7
7
- data.tar.gz: 2ce052dae89ccda7d9648d4ce2ea751b226281d7c7bb5ea3db369f52886e8ec83591941f0a58c1122067b81b2456b0b06a39217425b017f47dbfcce297378f8a
6
+ metadata.gz: 5862a5cc24a94a11a71ba2d649440d6636768b8b18872ae1f1653cfeef588d34d81069486cdb45bf9a2793a22bf9aef172df3bbf9f9e4fad243138b2be04f9b9
7
+ data.tar.gz: fc3048d404e60b186f3ab9bc49063369f98fd05f30a161ee5736ed116224ec544a3059218e60cf8eacccf1685f7a1f4bfaf15793569fc09d804b731a32e8ac27
data/Dockerfile.dummy ADDED
@@ -0,0 +1,40 @@
1
+ # ONLY FOR DEVELOPMENT PURPOSES
2
+ # dockerfile is not suitable to produce a production-grade docker image
3
+ FROM ruby:2.5.1
4
+
5
+ WORKDIR /opt/app
6
+
7
+ ADD https://dl.yarnpkg.com/debian/pubkey.gpg /tmp/yarn-pubkey.gpg
8
+ RUN apt-key add /tmp/yarn-pubkey.gpg && rm /tmp/yarn-pubkey.gpg
9
+ RUN echo 'deb http://dl.yarnpkg.com/debian/ stable main' > /etc/apt/sources.list.d/yarn.list
10
+
11
+ RUN apt-get update && apt-get install -qq -y --no-install-recommends \
12
+ build-essential libpq-dev curl
13
+
14
+ RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
15
+ RUN apt-get update && apt-get install -qq -y --no-install-recommends nodejs yarn
16
+
17
+ # Install chrome for integration tests
18
+ # RUN curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
19
+ # && dpkg -i google-chrome.deb || true \
20
+ # && apt-get install -f -y \
21
+ # && sed -i 's|HERE/chrome\"|HERE/chrome\" --disable-setuid-sandbox|g' /opt/google/chrome/google-chrome \
22
+ # && rm google-chrome.deb
23
+
24
+ ENV BUNDLE_PATH /bundle_box/bundle
25
+ ENV GEM_HOME /bundle_box/bundle
26
+ ENV PATH /bundle_box/bundle/bin:$PATH
27
+ # ENV NODE_PATH /bundle_box/node
28
+
29
+ COPY . .
30
+
31
+ # RUN bundle install
32
+ # RUN yarn install
33
+
34
+ # RUN mv .rbenv-vars.example .rbenv-vars
35
+ # RUN chmod +x entrypoint.sh
36
+
37
+ # ENV RAILS_ENV=development
38
+ # ENV PORT=3001
39
+ # EXPOSE 3001
40
+
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- marty (2.4.4)
4
+ marty (2.4.7)
5
5
  aws-sigv4 (~> 1.0, >= 1.0.2)
6
6
  axlsx (= 3.0.0pre)
7
7
  coderay
data/Makefile ADDED
@@ -0,0 +1,2 @@
1
+ include make-dummy.mk
2
+
data/README.md CHANGED
@@ -56,6 +56,22 @@ $ rake marty:delete_scripts
56
56
  Make sure that extjs is installed (or symbolically linked) in the
57
57
  dummy app at spec/dummy/public.
58
58
 
59
+ Docker doesn't support symlinks, so in order to run it in Docker you will have to copy extjs files.
60
+
61
+ ```bash
62
+ $ cp -r PATH/TO/YOUR/EXTJS/FILES spec/dummy/public/extjs
63
+ ```
64
+
65
+ You can run it with docker:
66
+
67
+ ```bash
68
+ $ make dummy-app-initialise-docker
69
+
70
+ $ make dummy-app-start
71
+ ```
72
+
73
+ To run without docker:
74
+
59
75
  Marty currently only runs with postgresql. To be able to run the tests
60
76
  you will first need to create a `database.yml` file in `spec/dummy/config`.
61
77
  You can use the example file by doing:
@@ -0,0 +1,23 @@
1
+ class Marty::DelayedJobController < ActionController::Base
2
+ def trigger
3
+ work_off_job if delayed_job.present?
4
+ render json: { status: :ok }, status: :ok
5
+ end
6
+
7
+ private
8
+
9
+ def delayed_job
10
+ return unless params['id'].present?
11
+ @delayed_job ||= ::Delayed::Job.find_by(id: params['id'])
12
+ end
13
+
14
+ def work_off_job
15
+ return if delayed_job.locked_at.present?
16
+
17
+ ::Delayed::Job.where(id: delayed_job.id).
18
+ update_all(locked_at: ::Delayed::Job.db_time_now, locked_by: 'Lambda')
19
+
20
+ w = ::Delayed::Worker.new
21
+ w.run(delayed_job)
22
+ end
23
+ end
@@ -25,7 +25,7 @@ class Marty::RpcController < ActionController::Base
25
25
  return result = massaged_params if massaged_params.include?(:error)
26
26
 
27
27
  api_params = api.process_params(massaged_params)
28
- auth = api.is_authorized?(massaged_params)
28
+ auth = api.is_authorized?(api_params)
29
29
  return result = {error: "Permission denied"} unless auth
30
30
 
31
31
  start_time = Time.zone.now
@@ -96,7 +96,8 @@ class Marty::DeloreanRule < Marty::BaseRule
96
96
  result.err_section)
97
97
  end
98
98
  result.cg_hash = Hash[result.cg_keys.zip(result.cg_vals)]
99
- return result.cg_hash.select{|k,v| !v} unless result.cg_vals.all?
99
+ fails = result.cg_hash.select{|k,v| ![v].flatten.first}
100
+ return fails if fails.present?
100
101
  end
101
102
 
102
103
  grids_computed = false
@@ -136,6 +136,8 @@ class Marty::Promise < Marty::Base
136
136
  end
137
137
 
138
138
  def wait_for_result(timeout)
139
+ # FIXME: Not sure that comparing result with empty hash if a good idea
140
+ # perhaps it's better to use .present? or .blank?
139
141
  return self.result if self.result != {}
140
142
 
141
143
  begin
@@ -148,25 +150,7 @@ class Marty::Promise < Marty::Base
148
150
  if !last.start_dt
149
151
  job = Marty::Promise.job_by_id(last.job_id)
150
152
 
151
- # log "AAAA #{Process.pid} #{last} #{job}"
152
-
153
- if !job || job.locked_at
154
- # job has been locked, so it looks like it started already
155
- # and we need to wait for it.
156
- wait_for_my_notify(Marty::Promise::DEFAULT_JOB_TIMEOUT)
157
- else
158
- # work off the job instead of waiting for a real worker to
159
- # pick it up.
160
- # log "OFF0 #{Process.pid} #{last}"
161
- begin
162
- work_off_job(job)
163
- rescue => exc
164
- # log "OFFERR #{exc}"
165
- res = Delorean::Engine.grok_runtime_exception(exc)
166
- last.set_result(res)
167
- end
168
- # log "OFF1 #{Process.pid} #{last}"
169
- end
153
+ wait_for_my_notify(Marty::Promise::DEFAULT_JOB_TIMEOUT)
170
154
 
171
155
  last = latest
172
156
 
@@ -184,19 +168,13 @@ class Marty::Promise < Marty::Base
184
168
  # at this point, we know the promise has already started
185
169
  if !last.end_dt
186
170
  wait_for_my_notify(timeout)
187
- # log "UUUU #{Process.pid} #{id} #{Time.now.to_f}"
188
171
  last = latest
189
172
 
190
- # log "XXXX #{Process.pid} #{Time.now.to_f} #{last}"
191
-
192
173
  if !last.end_dt
193
- # log "TO22 #{Process.pid} #{last}"
194
174
  return {"error" => "promise #{last.id} timed out (didn't end)"}
195
175
  end
196
176
  end
197
177
 
198
- # log "RRRR #{Process.pid} #{last} #{Time.now.to_f}"
199
-
200
178
  last.result
201
179
  ensure
202
180
  # Stop listening to the promise notifications
data/config/routes.rb CHANGED
@@ -6,5 +6,6 @@ Marty::Engine.routes.draw do
6
6
  match via: [:get, :post], "rpc/evaluate(.:format)" => "rpc", as: :rpc
7
7
  match via: [:get, :post], "report(.:format)" => "report#index", as: :report
8
8
  get 'job/download' => 'job', as: :job
9
+ post 'delayed_job/trigger' => 'delayed_job#trigger', as: :trigger_delayed_job
9
10
  get 'diag', to: 'diagnostic/#op'
10
11
  end
@@ -0,0 +1,41 @@
1
+ version: "2"
2
+
3
+ services:
4
+ app:
5
+ build:
6
+ context: .
7
+ dockerfile: Dockerfile.dummy
8
+ command: bash -c 'cd spec/dummy && rm -f tmp/pids/server.pid && rails s -b 0.0.0.0'
9
+ ports:
10
+ - "3000:3000"
11
+ environment:
12
+ - "PORT=3000"
13
+ - "PATH=/bundle_box/bundle/bin:/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
14
+ - "DEVELOPMENT_DATABASE_URL=postgres://postgres@postgres/marty_dev"
15
+ - "TEST_DATABASE_URL=postgres://postgres@postgres/marty_test"
16
+ # env_file: ".rbenv-vars"
17
+ depends_on:
18
+ - "postgres"
19
+ volumes:
20
+ - .:/opt/app:delegated
21
+
22
+ # - '~/.bash_history:/root/.bash_history'
23
+ # - '~/.pry_history:/root/.pry_history'
24
+ volumes_from:
25
+ - bundle_box
26
+ tty: true
27
+ stdin_open: true
28
+
29
+ postgres:
30
+ image: "clkao/postgres-plv8:9.6-2.0"
31
+ volumes:
32
+ - postgresql-data:/var/lib/postgresql/data
33
+
34
+ bundle_box:
35
+ image: busybox
36
+ volumes:
37
+ - /bundle_box
38
+
39
+ volumes:
40
+ postgresql-data:
41
+
@@ -107,6 +107,17 @@ class Marty::PromiseJob < Struct.new(:promise,
107
107
  # def log(msg)
108
108
  # open('/tmp/dj.out', 'a') { |f| f.puts msg }
109
109
  # end
110
+ #
111
+ def enqueue(job)
112
+ config = Rails.configuration.marty
113
+ hooks = config.promise_job_enqueue_hooks
114
+
115
+ return if hooks.blank?
116
+
117
+ hooks.each do |hook|
118
+ hook.call(job)
119
+ end
120
+ end
110
121
 
111
122
  def perform
112
123
  # log "PERF #{Process.pid} #{title}"
data/lib/marty/railtie.rb CHANGED
@@ -3,5 +3,6 @@ module Marty
3
3
  config.marty = ActiveSupport::OrderedOptions.new
4
4
  config.marty.default_posting_type = 'BASE'
5
5
  config.marty.extjs_theme = 'classic'
6
+ config.marty.promise_job_enqueue_hooks = []
6
7
  end
7
8
  end
data/lib/marty/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Marty
2
- VERSION = "2.4.5"
2
+ VERSION = "2.4.6"
3
3
  end
data/make-dummy.mk ADDED
@@ -0,0 +1,42 @@
1
+ dummy-app-build:
2
+ docker-compose --file=docker-compose.dummy.yml build
3
+
4
+ dummy-app:
5
+ docker-compose --file=docker-compose.dummy.yml up
6
+
7
+ dummy-app-start:
8
+ docker-compose --file=docker-compose.dummy.yml up app
9
+
10
+ dummy-app-stop:
11
+ docker-compose --file=docker-compose.dummy.yml stop
12
+
13
+ dummy-app-down:
14
+ docker-compose --file=docker-compose.dummy.yml down
15
+
16
+ dummy-app-bash:
17
+ docker-compose --file=docker-compose.dummy.yml run --rm app bash
18
+
19
+ dummy-app-console:
20
+ docker-compose --file=docker-compose.dummy.yml run --rm app bin/rails c
21
+
22
+ dummy-app-initialise-docker:
23
+ make dummy-app-install
24
+ make dummy-app-db-prepare
25
+
26
+ dummy-app-install:
27
+ make dummy-app-install-bundle
28
+
29
+ dummy-app-install-bundle:
30
+ docker-compose --file=docker-compose.dummy.yml run --rm app bundle
31
+
32
+ dummy-app-db-drop:
33
+ docker-compose --file=docker-compose.dummy.yml run --rm app rake db:drop
34
+
35
+ dummy-app-db-prepare:
36
+ cp spec/dummy/config/database.yml.example spec/dummy/config/database.yml
37
+ docker-compose --file=docker-compose.dummy.yml run --rm app bundle exec rake db:create db:migrate db:seed app:marty:load_scripts
38
+
39
+ dummy-app-db-seed:
40
+ docker-compose --file=docker-compose.dummy.yml run --rm app rake db:seed
41
+
42
+
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ require 'marty'
3
+ require 'delorean_lang'
4
+ require 'benchmark'
5
+ require 'job_helper'
6
+ require 'support/empty_job'
7
+
8
+ describe Marty::DelayedJobController, slow: false do
9
+ before(:each) { @routes = Marty::Engine.routes }
10
+
11
+ describe "#trigger" do
12
+ before do
13
+ @job = ::Delayed::Job.enqueue EmptyJob.new
14
+ end
15
+
16
+ it "should be able to execute existing job" do
17
+ expect(::Delayed::Job.exists?(@job.id)).to be true
18
+ post :trigger, params: { id: @job.id }
19
+ expect(response).to have_http_status(:ok)
20
+ expect(::Delayed::Job.exists?(@job.id)).to be false
21
+ end
22
+
23
+ it "should return ok if triggered job is locked" do
24
+ @job.update!(locked_at: Time.zone.now)
25
+ post :trigger, params: { id: @job.id }
26
+ expect(response).to have_http_status(:ok)
27
+ end
28
+
29
+ it "should return ok if triggered job is missing" do
30
+ @job.destroy!
31
+ post :trigger, params: { id: @job.id }
32
+ expect(response).to have_http_status(:ok)
33
+ end
34
+ end
35
+ end
@@ -3,8 +3,10 @@ common: &common
3
3
 
4
4
  development:
5
5
  <<: *common
6
+ url: <%= ENV['DEVELOPMENT_DATABASE_URL'] %>
6
7
  database: marty_dev
7
8
 
8
9
  test:
9
10
  <<: *common
10
11
  database: marty_test
12
+ url: <%= ENV['TEST_DATABASE_URL'] %>
@@ -10,6 +10,6 @@ Rule2,SimpleRule,2017-2-1 14:00:00,2017-4-1,true,"{""g_array"":[""G1V2""],""g_si
10
10
  Rule2a,SimpleRule,2017-2-1 14:00:00,2017-4-1,true,"{""g_array"":[""G1V2""],""g_single"":""G2V3"",""g_string"":""abc"",""g_bool"":true,""g_range"":""(,50]"",""g_integer"":99}",,,"{""simple_result"":""\""b value\"""", ""sr2"":""true"", ""sr3"": ""123""}"
11
11
  Rule2b,SimpleRule,2017-2-1 14:00:00,2017-4-1,true,"{""g_array"":[""G1V2""],""g_single"":""G2V3"",""g_string"":""abc"",""g_bool"":true,""g_range"":""(,50]"",""g_integer"":999}",,"{""grid1"":""DataGrid1"",""grid2"":""DataGrid2""}",
12
12
  Rule2c,SimpleRule,2017-2-1 14:00:00,2017-4-1,true,"{""g_array"":[""G1V2""],""g_single"":""G2V3"",""g_string"":""abc"",""g_bool"":false,""g_range"":""(,50]"",""g_integer"":10}",,"{""grid1"":""DataGrid1"",""grid2"":""DataGrid2""}",
13
- Rule3,ComplexRule,2017-3-1 00:00:00,2017-4-1,false,"{""g_array"":[""G1V2"",""G1V3""],""g_string"":""def"",""g_integer"":11}","{""cguard1"":""1==1"",""cguard2"":""param2 == 'abc'""}","{""grid1"":""DataGrid1"",""grid2"":""DataGrid2""}","{""simple_result"":""\""c value\"""",""computed_value"":""if paramb\nthen param1 / (grid1_grid_result||1)\nelse (grid2_grid_result||1) / param1""}"
13
+ Rule3,ComplexRule,2017-3-1 00:00:00,2017-4-1,false,"{""g_array"":[""G1V2"",""G1V3""],""g_string"":""def"",""g_integer"":11}","{""cguard1"":""1==1"",""cguard2"":""[param2 == 'abc', \""a string\""]""}","{""grid1"":""DataGrid1"",""grid2"":""DataGrid2""}","{""simple_result"":""\""c value\"""",""computed_value"":""if paramb\nthen param1 / (grid1_grid_result||1)\nelse (grid2_grid_result||1) / param1""}"
14
14
  Rule4,ComplexRule,2017-4-1 15:00:01,2017-5-1,,"{""g_array"":[""G1V2"",""G1V3""],""g_string"":""Hi Mom"",""g_integer"":11}","{""cguard1"":""1==1"",""cguard2"":""param2 == \""abc\""""}","{""grid1"":""DataGrid1"",""grid2"":""DataGrid2""}","{""computed_name_grid"":""\""DataGrid\""+\""X\"""", ""simple_result"":""computed_name_grid"",""grid_sum"":""computed_name_grid_result + (grid1_grid_result||0)+(grid2_grid_result||0)""}"
15
- Rule5,ComplexRule,2017-4-2 15:00:01,2017-5-1,,"{""g_string"":""zzz"",""g_integer"":3757,""g_has_default"":""foo""}","{""cguard1"":""1==1""}",,"{""flavor"": ""[\""cherry\"",\""lemon\""][param2]"",""other_grid"": ""\""DataGrid4\"""",""final_value"": ""other_grid_result * 3""}"
15
+ Rule5,ComplexRule,2017-4-2 15:00:01,2017-5-1,,"{""g_string"":""zzz"",""g_integer"":3757,""g_has_default"":""foo""}","{""cguard1"":""[1==1, \""a string\""]""}",,"{""flavor"": ""[\""cherry\"",\""lemon\""][param2]"",""other_grid"": ""\""DataGrid4\"""",""final_value"": ""other_grid_result * 3""}"
@@ -15,8 +15,12 @@ module Marty
15
15
  end
16
16
 
17
17
  it "log has its own connection" do
18
- expect(Marty::Log.connection).not_to equal(Marty::Posting.connection)
19
- expect(Marty::Posting.connection).to equal(Marty::Script.connection)
18
+ log_conn = Marty::Log.connection.raw_connection
19
+ posting_conn = Marty::Posting.connection.raw_connection
20
+ script_conn = Marty::Script.connection.raw_connection
21
+
22
+ expect(log_conn).not_to equal(posting_conn)
23
+ expect(posting_conn).to equal(script_conn)
20
24
  end
21
25
 
22
26
  it "logs" do
@@ -286,7 +286,7 @@ module Marty::RuleSpec
286
286
  it "computed guards work" do
287
287
  c = complex.compute(@ruleopts_myrule, {"pt"=>Time.zone.now,
288
288
  'param2'=>'def'})
289
- expect(c).to eq({"cguard2"=>false})
289
+ expect(c).to eq({"cguard2"=>[false, "a string"]})
290
290
  end
291
291
  it "returns simple results via #fixed_results" do
292
292
  expect(simple.fixed_results["simple_result"]).to eq("b value")
@@ -0,0 +1,5 @@
1
+ # Used for testing delayed job triggers
2
+ class EmptyJob
3
+ def perform
4
+ end
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marty
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.5
4
+ version: 2.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arman Bostani
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2018-12-10 00:00:00.000000000 Z
17
+ date: 2019-01-09 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: pg
@@ -186,10 +186,12 @@ files:
186
186
  - ".gitignore"
187
187
  - ".rspec"
188
188
  - ".travis.yml"
189
+ - Dockerfile.dummy
189
190
  - Gemfile
190
191
  - Gemfile.lock
191
192
  - INDEPENDENCE_ISSUES.md
192
193
  - MIT-LICENSE
194
+ - Makefile
193
195
  - README.md
194
196
  - Rakefile
195
197
  - app/assets/images/marty/.gitkeep
@@ -401,6 +403,7 @@ files:
401
403
  - app/components/marty/user_view.rb
402
404
  - app/controllers/marty/application_controller.rb
403
405
  - app/controllers/marty/components_controller.rb
406
+ - app/controllers/marty/delayed_job_controller.rb
404
407
  - app/controllers/marty/diagnostic/controller.rb
405
408
  - app/controllers/marty/job_controller.rb
406
409
  - app/controllers/marty/report_controller.rb
@@ -488,6 +491,7 @@ files:
488
491
  - db/seeds.rb
489
492
  - delorean/diagnostics.dl
490
493
  - delorean/script_report.dl
494
+ - docker-compose.dummy.yml
491
495
  - gemini_deprecations.md
492
496
  - lib/marty.rb
493
497
  - lib/marty/aws/base.rb
@@ -520,6 +524,7 @@ files:
520
524
  - lib/pyxll/pyxll.cfg
521
525
  - lib/pyxll/sample.xlsx
522
526
  - lib/tasks/marty_tasks.rake
527
+ - make-dummy.mk
523
528
  - marty.gemspec
524
529
  - other/marty/api/base.rb
525
530
  - other/marty/diagnostic/aws/ec2_instance.rb
@@ -540,6 +545,7 @@ files:
540
545
  - other/marty/diagnostic/version.rb
541
546
  - script/rails
542
547
  - spec/controllers/application_controller_spec.rb
548
+ - spec/controllers/delayed_job_controller_spec.rb
543
549
  - spec/controllers/diagnostic/controller_spec.rb
544
550
  - spec/controllers/job_controller_spec.rb
545
551
  - spec/controllers/rpc_controller_spec.rb
@@ -1693,6 +1699,7 @@ files:
1693
1699
  - spec/support/custom_selectors.rb
1694
1700
  - spec/support/delayed_job_helpers.rb
1695
1701
  - spec/support/download_helper.rb
1702
+ - spec/support/empty_job.rb
1696
1703
  - spec/support/helper.rb
1697
1704
  - spec/support/netzke.rb
1698
1705
  - spec/support/performance_helper.rb
@@ -1723,7 +1730,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1723
1730
  version: '0'
1724
1731
  requirements: []
1725
1732
  rubyforge_project:
1726
- rubygems_version: 2.7.7
1733
+ rubygems_version: 2.6.14
1727
1734
  signing_key:
1728
1735
  specification_version: 4
1729
1736
  summary: A framework for working with versioned data