rapidflow 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -1
- data/README.md +78 -63
- data/lib/rapidflow/batch.rb +9 -25
- data/lib/rapidflow/batch_builder.rb +16 -0
- data/lib/rapidflow/counter.rb +1 -1
- data/lib/rapidflow/errors.rb +7 -0
- data/lib/rapidflow/pipeline.rb +1 -1
- data/lib/rapidflow/stage.rb +9 -1
- data/lib/rapidflow/version.rb +2 -2
- data/lib/rapidflow/work_item.rb +1 -1
- data/lib/rapidflow.rb +3 -1
- data/scripts/benchmark/benchmark_api_request_process_and_storing.rb +11 -11
- data/scripts/benchmark/benchmark_images.rb +6 -6
- data/scripts/benchmark/simulated_data_processing.rb +6 -6
- data/sig/rapidflow.rbs +1 -1
- data/test/rapidflow/batch/config_error_test.rb +43 -0
- data/test/rapidflow/batch/error_handling_test.rb +211 -0
- data/test/rapidflow/batch_test.rb +71 -222
- data/test/rapidflow/counter_test.rb +1 -1
- data/test/rapidflow/pipeline_test.rb +67 -0
- data/test/rapidflow/stage_test.rb +110 -0
- data/test/rapidflow/work_item_test.rb +1 -1
- metadata +7 -2
- data/.github/workflows/main.yml +0 -35
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
module RapidFlow
|
|
6
|
+
class StageTest < Minitest::Test
|
|
7
|
+
def test_stage_processes_single_item
|
|
8
|
+
pipeline = Pipeline.new(1, 1)
|
|
9
|
+
work_item = WorkItem.new(data: 5)
|
|
10
|
+
|
|
11
|
+
stage = Stage.new(
|
|
12
|
+
stage_index: 0,
|
|
13
|
+
lambda_fn: ->(data) { data * 2 },
|
|
14
|
+
workers: 1,
|
|
15
|
+
is_final: true,
|
|
16
|
+
pipeline: pipeline
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
stage.start
|
|
20
|
+
pipeline.enqueue(0, work_item)
|
|
21
|
+
|
|
22
|
+
result = pipeline.dequeue_result
|
|
23
|
+
pipeline.shutdown
|
|
24
|
+
|
|
25
|
+
assert_equal 10, result.data
|
|
26
|
+
refute result.has_error?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_stage_handles_errors
|
|
30
|
+
pipeline = Pipeline.new(1, 1)
|
|
31
|
+
work_item = WorkItem.new(data: "test")
|
|
32
|
+
|
|
33
|
+
stage = Stage.new(
|
|
34
|
+
stage_index: 0,
|
|
35
|
+
lambda_fn: ->(_data) { raise StandardError, "Processing error" },
|
|
36
|
+
workers: 1,
|
|
37
|
+
is_final: true,
|
|
38
|
+
pipeline: pipeline
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
stage.start
|
|
42
|
+
pipeline.enqueue(0, work_item)
|
|
43
|
+
|
|
44
|
+
result = pipeline.dequeue_result
|
|
45
|
+
pipeline.shutdown
|
|
46
|
+
|
|
47
|
+
assert_equal "test", result.data
|
|
48
|
+
assert result.has_error?
|
|
49
|
+
assert_instance_of StandardError, result.error
|
|
50
|
+
assert_equal "Processing error", result.error.message
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_stage_with_multiple_workers
|
|
54
|
+
pipeline = Pipeline.new(1, 3)
|
|
55
|
+
items = 10.times.map { |i| WorkItem.new(data: i) }
|
|
56
|
+
|
|
57
|
+
stage = Stage.new(
|
|
58
|
+
stage_index: 0,
|
|
59
|
+
lambda_fn: ->(data) { data * 2 },
|
|
60
|
+
workers: 3,
|
|
61
|
+
is_final: true,
|
|
62
|
+
pipeline: pipeline
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
stage.start
|
|
66
|
+
items.each { |item| pipeline.enqueue(0, item) }
|
|
67
|
+
|
|
68
|
+
results = []
|
|
69
|
+
10.times { results << pipeline.dequeue_result }
|
|
70
|
+
pipeline.shutdown
|
|
71
|
+
|
|
72
|
+
assert_equal 10, results.length
|
|
73
|
+
results.each do |result|
|
|
74
|
+
refute result.has_error?
|
|
75
|
+
assert_includes (0..9).map { |i| i * 2 }, result.data
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def test_stage_forwards_to_next_stage
|
|
80
|
+
pipeline = Pipeline.new(2, 1)
|
|
81
|
+
work_item = WorkItem.new(data: "hello")
|
|
82
|
+
|
|
83
|
+
stage1 = Stage.new(
|
|
84
|
+
stage_index: 0,
|
|
85
|
+
lambda_fn: ->(data) { data.upcase },
|
|
86
|
+
workers: 1,
|
|
87
|
+
is_final: false,
|
|
88
|
+
pipeline: pipeline
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
stage2 = Stage.new(
|
|
92
|
+
stage_index: 1,
|
|
93
|
+
lambda_fn: ->(data) { data + "!" },
|
|
94
|
+
workers: 1,
|
|
95
|
+
is_final: true,
|
|
96
|
+
pipeline: pipeline
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
stage1.start
|
|
100
|
+
stage2.start
|
|
101
|
+
pipeline.enqueue(0, work_item)
|
|
102
|
+
|
|
103
|
+
result = pipeline.dequeue_result
|
|
104
|
+
pipeline.shutdown
|
|
105
|
+
|
|
106
|
+
assert_equal "HELLO!", result.data
|
|
107
|
+
refute result.has_error?
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rapidflow
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sinaru Gunawardena
|
|
@@ -17,7 +17,6 @@ executables: []
|
|
|
17
17
|
extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
|
19
19
|
files:
|
|
20
|
-
- ".github/workflows/main.yml"
|
|
21
20
|
- ".tool-versions"
|
|
22
21
|
- CHANGELOG.md
|
|
23
22
|
- CODE_OF_CONDUCT.md
|
|
@@ -26,7 +25,9 @@ files:
|
|
|
26
25
|
- Rakefile
|
|
27
26
|
- lib/rapidflow.rb
|
|
28
27
|
- lib/rapidflow/batch.rb
|
|
28
|
+
- lib/rapidflow/batch_builder.rb
|
|
29
29
|
- lib/rapidflow/counter.rb
|
|
30
|
+
- lib/rapidflow/errors.rb
|
|
30
31
|
- lib/rapidflow/pipeline.rb
|
|
31
32
|
- lib/rapidflow/stage.rb
|
|
32
33
|
- lib/rapidflow/version.rb
|
|
@@ -35,8 +36,12 @@ files:
|
|
|
35
36
|
- scripts/benchmark/benchmark_images.rb
|
|
36
37
|
- scripts/benchmark/simulated_data_processing.rb
|
|
37
38
|
- sig/rapidflow.rbs
|
|
39
|
+
- test/rapidflow/batch/config_error_test.rb
|
|
40
|
+
- test/rapidflow/batch/error_handling_test.rb
|
|
38
41
|
- test/rapidflow/batch_test.rb
|
|
39
42
|
- test/rapidflow/counter_test.rb
|
|
43
|
+
- test/rapidflow/pipeline_test.rb
|
|
44
|
+
- test/rapidflow/stage_test.rb
|
|
40
45
|
- test/rapidflow/work_item_test.rb
|
|
41
46
|
- test/test_helper.rb
|
|
42
47
|
homepage: https://github.com/sinaru/rapidflow
|
data/.github/workflows/main.yml
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# This workflow uses actions that are not certified by GitHub.
|
|
2
|
-
# They are provided by a third-party and are governed by
|
|
3
|
-
# separate terms of service, privacy policy, and support
|
|
4
|
-
# documentation.
|
|
5
|
-
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
|
6
|
-
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
|
7
|
-
|
|
8
|
-
name: Ruby
|
|
9
|
-
|
|
10
|
-
on:
|
|
11
|
-
push:
|
|
12
|
-
branches: [ "main" ]
|
|
13
|
-
pull_request:
|
|
14
|
-
branches: [ "main" ]
|
|
15
|
-
|
|
16
|
-
permissions:
|
|
17
|
-
contents: read
|
|
18
|
-
|
|
19
|
-
jobs:
|
|
20
|
-
test:
|
|
21
|
-
|
|
22
|
-
runs-on: ubuntu-latest
|
|
23
|
-
strategy:
|
|
24
|
-
matrix:
|
|
25
|
-
ruby-version: ['3.2','3.3','3.4']
|
|
26
|
-
|
|
27
|
-
steps:
|
|
28
|
-
- uses: actions/checkout@v5
|
|
29
|
-
- name: Set up Ruby
|
|
30
|
-
uses: ruby/setup-ruby@v1
|
|
31
|
-
with:
|
|
32
|
-
ruby-version: ${{ matrix.ruby-version }}
|
|
33
|
-
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
34
|
-
- name: Run tests
|
|
35
|
-
run: bundle exec rake test
|