little_monster 0.1.7 → 0.1.9

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: a5fe4a4fb228c4c34cf4084d3e679ea3338423f5
4
- data.tar.gz: 33d5b1ab1f908282da6d82a34775393e7db9c357
3
+ metadata.gz: 11689957621c432567c76283d4d534c4489ca928
4
+ data.tar.gz: ad919ed6292c894d52d473c04103061c88625451
5
5
  SHA512:
6
- metadata.gz: 84ceda610dfd1ee6e0d6edff7ad5a3de3a81f0e6b14771cadf7c5f66d56125162988ad7bc7ccf3e049eea48056cc25083155281f8fa1c8c8d215bd836f77f19e
7
- data.tar.gz: bcb0ce751eb61f6f03219d7774e27cd5a1450b26788ba9485e6bdafb2abf9f4e7fc44f936dc3b26cc2a12a4e54ff6ac56d8ffefe46e8a3f99cf23e40dd342b87
6
+ metadata.gz: 1133c898fe47757c8f1828947d2c37a447594f57626db250a6eb6ee3b06a2cb4086fbfe32df9a893c7bd257e38c8ad11b84b5f2d29130653b3a82a318cac2a03
7
+ data.tar.gz: 31a3cda7700de906ff6a52aade9ffb2c13fcbdbb201dbe645483c240ac8bf6cb17ee8acaedec861aadce12f9d475fc893eac52e76f6bbcc85a7efcffaa52e807
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- little_monster (0.1.7)
4
+ little_monster (0.1.9)
5
5
  activesupport
6
6
  multi_json
7
7
  thor
data/README.md CHANGED
@@ -3,3 +3,90 @@
3
3
  [![Code Climate](https://codeclimate.com/github/mercadolibre/fury-little_monster-gem/badges/gpa.svg)](https://codeclimate.com/github/mercadolibre/fury-little_monster-gem)
4
4
  # fury-little_monster
5
5
 
6
+ ##RSPEC Matchers
7
+
8
+ ###Installation
9
+
10
+ in your spec_helper add the following line
11
+
12
+ ```ruby
13
+ require 'little_monster/rspec'
14
+ ```
15
+
16
+ ###helpers
17
+
18
+ ### generate_job
19
+ it takes a job and a hash of parameters and returns a fully configured job instance
20
+
21
+ #### generate_job with data
22
+ ```ruby
23
+ generate_job :my_job, data: { a: :b }
24
+ ```
25
+
26
+ #### generate_job with task mocked to fail
27
+ ```ruby
28
+ generate_job :my_job, data: { a: :b }, fails: { task: :my_task, error: MyError.new }
29
+ ```
30
+
31
+ #### generate_job with multiples tasks mocked to fail
32
+ ```ruby
33
+ generate_job :my_job, data: { a: :b }, fails: [{ task: :my_task, error: MyError.new }, { task: :my_other_task, error: MyError.new }]
34
+ ```
35
+
36
+ ### run_job
37
+ given a generated job, it returns a JobResult object to make expectation about the run
38
+
39
+ ### generate_task
40
+ it takes a task class or symbol and returns a fully configured task instance
41
+
42
+ #### generate_task with data
43
+ ```ruby
44
+ generate_task MyJob::MyTask, data: { a: :b }
45
+ ```
46
+
47
+ ###matchers
48
+
49
+ ###have_run
50
+
51
+ given a JobResult object expects the job to run that list of tasks
52
+ ```ruby
53
+ expect(run_job(:my_job)).to have_run(:my_task, :my_other_task)
54
+ ```
55
+
56
+ ###have_run_task
57
+
58
+ given a JobResult object expects the job to run the a given task with a certain data
59
+ ```ruby
60
+ expect(run_job(:my_job)).to have_run_task(:my_task).with_data(a: :b)
61
+ ```
62
+
63
+ ###have_ended_with_status
64
+
65
+ given a JobResult object expects the job have a given status after the run
66
+ ```ruby
67
+ expect(run_job(:my_job)).to have_ended_with_status(:success)
68
+ ```
69
+
70
+ ###have_data
71
+
72
+ given checks a job or JobResult instance data
73
+ ```ruby
74
+ expect(run_job(:my_job)).to have_ended_with_status(:success)
75
+ ```
76
+ ```ruby
77
+ expect(generate_job(:my_job)).to have_ended_with_status(:success)
78
+ ```
79
+
80
+ ###have_retries
81
+
82
+ given job instance, a class or a class symbol it expects the retries for that class
83
+ ```ruby
84
+ expect(:my_job).to have_retries(3)
85
+ ```
86
+
87
+ ###have_retries
88
+
89
+ given job instance, a class or a class symbol it expects the callback retries for that class
90
+ ```ruby
91
+ expect(my_job).to have_callback_retries(10)
92
+ ```
@@ -1,5 +1,6 @@
1
1
  require 'typhoeus'
2
2
  require 'multi_json'
3
+ require 'securerandom'
3
4
 
4
5
  module LittleMonster::Core
5
6
  class API
@@ -29,20 +30,27 @@ module LittleMonster::Core
29
30
  def request(method, path, params = {}, retries: LittleMonster.default_request_retries,
30
31
  retry_wait: LittleMonster.default_request_retry_wait,
31
32
  critical: false)
33
+
34
+ request_id = SecureRandom.uuid
32
35
  ret = 0
33
36
  res = nil
34
37
  url = [LittleMonster.api_url.chomp('/'), path.sub(/\//, '')].join '/'
35
38
 
36
39
  params[:body] = MultiJson.dump params.fetch(:body, {}) unless params[:body].is_a? String
40
+
37
41
  params[:headers] ||= {}
38
42
  params[:headers]['Content-Type'] = 'application/json' unless params[:headers]['Content-Type']
43
+ params[:headers]['X-Request-ID'] = request_id
44
+
39
45
  params[:timeout] = LittleMonster.request_timeout
40
46
 
41
47
  begin
42
48
  res = Typhoeus.public_send method, url, params
43
49
  if res.code >= 500 || res.code.zero?
44
- raise FuryHttpApiError, "request to #{res.effective_url} failed with status #{res.code} retry #{ret}"
50
+ raise FuryHttpApiError, "[type:request_failed][request_id:#{request_id}] request to #{res.effective_url} failed with status #{res.code} retry #{ret}"
45
51
  end
52
+
53
+ logger.info "[type:request_log][request_id:#{request_id}] request made to #{url} with [status:#{res.code}]"
46
54
  rescue StandardError => e
47
55
  logger.error e.message
48
56
  if ret < retries
@@ -51,11 +59,11 @@ module LittleMonster::Core
51
59
  retry
52
60
  end
53
61
 
54
- logger.error "[type:request_max_retries_reached][url:#{url}][retries:#{ret}] request has reached max retries"
62
+ logger.error "[type:request_max_retries_reached][request_id:#{request_id}][url:#{url}][retries:#{ret}] request has reached max retries"
55
63
 
56
64
  if critical
57
- logger.error "[type:critical_request_failed][url:#{url}][retries:#{ret}] request has reached max retries"
58
- raise APIUnreachableError, "critical request to #{url} has fail, check little monster api"
65
+ logger.error "[type:critical_request_failed][request_id:#{request_id}][url:#{url}][retries:#{ret}] request has reached max retries"
66
+ raise APIUnreachableError, "[request_id:#{request_id}] critical request to #{url} has fail, check little monster api"
59
67
  end
60
68
  end
61
69
 
@@ -13,7 +13,7 @@ module LittleMonster::Core::Counters
13
13
  logger.error "Could not increase counter #{counter_name}, Api unreachable"
14
14
  raise e
15
15
  end
16
- raise DuplicatedCounterError if resp.code == 412
16
+ #raise DuplicatedCounterError if resp.code == 412
17
17
  true
18
18
  end
19
19
 
@@ -2,7 +2,7 @@ module LittleMonster::RSpec::Matchers
2
2
  class HaveRun
3
3
  def initialize(*expected_tasks)
4
4
  @expected_tasks = if expected_tasks.length == 1
5
- expected_tasks.first
5
+ [expected_tasks.first].flatten
6
6
  else
7
7
  expected_tasks
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module LittleMonster
2
- VERSION = '0.1.7'.freeze
2
+ VERSION = '0.1.9'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: little_monster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - arq
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-23 00:00:00.000000000 Z
11
+ date: 2016-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport