chaotic_job 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: d7a3e97903b960aad5ff163a8ea80d3d1c94d8427e86d0d06cb6c44ceffd7ad4
4
- data.tar.gz: b4c2200a5436d1575f0f66d8647834514bd6563ac3fbf62a74014557d198ed90
3
+ metadata.gz: b82a52379f9efe41b3243e19904fa96e0cc8703bf813a42401b74128242ea6a2
4
+ data.tar.gz: b4979b0ba3ddec6e2c8ab680458853a7ffeda84e25af95e6858d16846f5d77b2
5
5
  SHA512:
6
- metadata.gz: fa8f9e58bf1fa3eab4e4b6441e91824322e02043daea6fccb7f4d21844c739b34d376880ef03924fed43a7f7d49cf72fa536400698216ca58247cb287c49abd6
7
- data.tar.gz: f8e83e868e13ed287f1ae9ff3b2560257b5c6fe1e6ba715bf400a93d2148c5a36d9372ac70aaadb5a498db198b3a0f0d9cd4bb3c00d138aa0ac4a8961c1e463a
6
+ metadata.gz: 0f38bed8995ac63a1755dcb316c3886dcf32cb5fb953aec4d3be8ce4b3b7690c76febacc458fc05ca2e30ef8b67947a4b639f7035e8cea7aac84d59bd1da37a3
7
+ data.tar.gz: 616f9d8543fa39d00e30f82bd20edb22ddae4578f4c0e9a7557135b599002f9dbdc29a64bba6c25471a76f489004556745e3708310789d6f716fe9c879ccd2ff
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.1] - 2024-11-06
4
+
5
+ - Update `Journal` interface
6
+ - Add top-level `ChaoticJob` methods to work with the journal
7
+ - Fix bug with job sorting in the `Performer`
8
+ - Fix bug with resolving time cutoffs in the `Performer`
9
+ - Fix bug with using the `run_scenario` helper with a block
10
+
3
11
  ## [0.1.0] - 2024-11-06
4
12
 
5
13
  - Added `Journal` to log activity for tests
data/README.md CHANGED
@@ -115,10 +115,10 @@ end
115
115
  > |---|---|
116
116
  > | `Journal.log` | log simply that something happened within the default scope |
117
117
  > | `Journal.log(thing, scope: :special)` | log a particular value within a particular scope |
118
- > | `Journal.total` | get the total number of logs under the default scope |
119
- > | `Journal.total(scope: :special)` | get the total number of logs under a particular scope |
120
- > | `Journal.all` | get all of the logged values under the default scope |
121
- > | `Journal.all(scope: :special)` | get all of the logged values under a particular scope |
118
+ > | `Journal.size` | get the total number of logs under the default scope |
119
+ > | `Journal.size(scope: :special)` | get the total number of logs under a particular scope |
120
+ > | `Journal.entries` | get all of the logged values under the default scope |
121
+ > | `Journal.entries(scope: :special)` | get all of the logged values under a particular scope |
122
122
 
123
123
  In this example, the job being tested is defined within the test case. You can, of course, also test jobs defined in your application. The key detail is the `glitch` keyword argument. A "glitch" is simply a tuple that describes precisely where you would like the failure to occur. The first element of the tuple is the location of the glitch, which can be either *before* or *after*. The second element is the location of the code that will be affected by the glitch, defined by its file path and line number. What this example scenario does is inject a glitch before the `step_3` method is called, here:
124
124
 
@@ -20,12 +20,16 @@ module ChaoticJob
20
20
  @logs[scope] << item
21
21
  end
22
22
 
23
- def total(scope: :default)
23
+ def size(scope: :default)
24
24
  @logs[scope]&.size || 0
25
25
  end
26
26
 
27
- def all(scope: :default)
27
+ def entries(scope: :default)
28
28
  @logs[scope]
29
29
  end
30
+
31
+ def top(scope: :default)
32
+ entries&.first
33
+ end
30
34
  end
31
35
  end
@@ -40,7 +40,17 @@ module ChaoticJob
40
40
 
41
41
  def enqueued_jobs_where(before: nil, after: nil)
42
42
  enqueued_jobs
43
- .sort_by { |job| job["scheduled_at"] }
43
+ .sort do |ljob, rjob|
44
+ lat = ljob[:at]
45
+ rat = rjob[:at]
46
+
47
+ # sort by scheduled time, with nil values first
48
+ if lat && rat
49
+ lat <=> rat
50
+ else
51
+ lat ? 1 : -1
52
+ end
53
+ end
44
54
  .select do |job|
45
55
  scheduled_at = job[:at]
46
56
 
@@ -67,7 +77,7 @@ module ChaoticJob
67
77
  in Time
68
78
  cutoff
69
79
  end
70
- delta = (Time.now - time).abs
80
+ delta = (Time.now - time).abs.floor
71
81
  changeset = case delta
72
82
  when 0..59 # seconds
73
83
  {usec: 0}
@@ -16,15 +16,15 @@ module ChaoticJob
16
16
  @events = []
17
17
  end
18
18
 
19
- def run
19
+ def run(&block)
20
20
  @job.class.retry_on RetryableError, attempts: 10, wait: 1, jitter: 0
21
21
 
22
22
  ActiveSupport::Notifications.subscribed(->(event) { @events << event.dup }, @capture) do
23
23
  glitch.inject! do
24
- if block_given?
25
- yield
24
+ @job.enqueue
25
+ if block
26
+ block.call
26
27
  else
27
- @job.enqueue
28
28
  Performer.perform_all
29
29
  end
30
30
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChaoticJob
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/chaotic_job.rb CHANGED
@@ -11,6 +11,34 @@ module ChaoticJob
11
11
  class RetryableError < StandardError
12
12
  end
13
13
 
14
+ def self.log_to_journal!(item = nil, scope: nil)
15
+ if item && scope
16
+ Journal.log(item, scope: scope)
17
+ elsif item
18
+ Journal.log(item)
19
+ elsif scope
20
+ Journal.log(scope: scope)
21
+ else
22
+ Journal.log
23
+ end
24
+ end
25
+
26
+ def self.journal_size(scope: nil)
27
+ if scope
28
+ Journal.size(scope: scope)
29
+ else
30
+ Journal.size
31
+ end
32
+ end
33
+
34
+ def self.top_journal_entry(scope: nil)
35
+ if scope
36
+ Journal.top(scope: scope)
37
+ else
38
+ Journal.top
39
+ end
40
+ end
41
+
14
42
  module Helpers
15
43
  def perform_all
16
44
  Performer.perform_all
@@ -36,11 +64,15 @@ module ChaoticJob
36
64
  Simulation.new(job, **kwargs).run(&block)
37
65
  end
38
66
 
39
- def run_scenario(job, glitch: nil, glitches: nil, raise: nil, capture: nil)
67
+ def run_scenario(job, glitch: nil, glitches: nil, raise: nil, capture: nil, &block)
40
68
  kwargs = {glitches: glitches || [glitch]}
41
69
  kwargs[:raise] = raise if raise
42
70
  kwargs[:capture] = capture if capture
43
- Scenario.new(job, **kwargs).run
71
+ if block
72
+ Scenario.new(job, **kwargs).run(&block)
73
+ else
74
+ Scenario.new(job, **kwargs).run
75
+ end
44
76
  end
45
77
  end
46
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chaotic_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Margheim