tiny_conveyor 0.0.1

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.
data/icon.png ADDED
Binary file
data/icon.svg ADDED
@@ -0,0 +1,121 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <svg
3
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
4
+ xmlns:cc="http://creativecommons.org/ns#"
5
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
6
+ xmlns:svg="http://www.w3.org/2000/svg"
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
9
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
10
+ height="512"
11
+ viewBox="0 0 512 512"
12
+ width="512"
13
+ version="1.1"
14
+ id="svg43"
15
+ sodipodi:docname="delivery(1).svg"
16
+ inkscape:version="1.0.2 (e86c8708, 2021-01-15)">
17
+ <metadata
18
+ id="metadata49">
19
+ <rdf:RDF>
20
+ <cc:Work
21
+ rdf:about="">
22
+ <dc:format>image/svg+xml</dc:format>
23
+ <dc:type
24
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
25
+ </cc:Work>
26
+ </rdf:RDF>
27
+ </metadata>
28
+ <defs
29
+ id="defs47" />
30
+ <sodipodi:namedview
31
+ pagecolor="#ffffff"
32
+ bordercolor="#666666"
33
+ borderopacity="1"
34
+ objecttolerance="10"
35
+ gridtolerance="10"
36
+ guidetolerance="10"
37
+ inkscape:pageopacity="0"
38
+ inkscape:pageshadow="2"
39
+ inkscape:window-width="1440"
40
+ inkscape:window-height="847"
41
+ id="namedview45"
42
+ showgrid="false"
43
+ inkscape:zoom="1.3027344"
44
+ inkscape:cx="256"
45
+ inkscape:cy="256"
46
+ inkscape:window-x="0"
47
+ inkscape:window-y="25"
48
+ inkscape:window-maximized="1"
49
+ inkscape:current-layer="svg43" />
50
+ <g
51
+ id="Delivery-3"
52
+ data-name="Delivery">
53
+ <path
54
+ d="m464 264h-416a32 32 0 0 0 -32 32v16a32 32 0 0 0 32 32h416a32 32 0 0 0 32-32v-16a32 32 0 0 0 -32-32zm-408 56a16 16 0 1 1 16-16 16 16 0 0 1 -16 16zm104 0a16 16 0 1 1 16-16 16 16 0 0 1 -16 16zm96 0a16 16 0 1 1 16-16 16 16 0 0 1 -16 16zm96 0a16 16 0 1 1 16-16 16 16 0 0 1 -16 16zm104 0a16 16 0 1 1 16-16 16 16 0 0 1 -16 16z"
55
+ fill="#57a4ff"
56
+ id="path10"
57
+ style="fill:#c83737" />
58
+ <path
59
+ d="m256 152v56l-24-16-24 16v-56z"
60
+ fill="#57a4ff"
61
+ id="path12" />
62
+ <path
63
+ d="m256 152v56l-24-16-24 16v-56z"
64
+ fill="#57a4ff"
65
+ id="path14"
66
+ style="fill:#c83737" />
67
+ <path
68
+ d="m400 152v56l-24-16-24 16v-56z"
69
+ fill="#57a4ff"
70
+ id="path16" />
71
+ <path
72
+ d="m400 152v56l-24-16-24 16v-56z"
73
+ fill="#57a4ff"
74
+ id="path18"
75
+ style="fill:#c83737" />
76
+ <g
77
+ fill="#004fac"
78
+ id="g40">
79
+ <path
80
+ d="m464 256h-24v-104a8 8 0 0 0 -8-8h-112a8 8 0 0 0 -8 8v104h-16v-104a8 8 0 0 0 -8-8h-112a8 8 0 0 0 -8 8v104h-120a40.045 40.045 0 0 0 -40 40v16a40.045 40.045 0 0 0 40 40h416a40.045 40.045 0 0 0 40-40v-16a40.045 40.045 0 0 0 -40-40zm-72-96v33.052l-11.562-7.708a8 8 0 0 0 -8.876 0l-11.562 7.708v-33.052zm-64 0h16v48a8 8 0 0 0 12.438 6.656l19.562-13.041 19.562 13.041a8 8 0 0 0 12.438-6.656v-48h16v96h-96zm-80 0v33.052l-11.562-7.708a8 8 0 0 0 -8.876 0l-11.562 7.708v-33.052zm-64 0h16v48a8 8 0 0 0 12.438 6.656l19.562-13.041 19.562 13.041a8 8 0 0 0 12.438-6.656v-48h16v96h-96zm304 152a24.027 24.027 0 0 1 -24 24h-416a24.027 24.027 0 0 1 -24-24v-16a24.027 24.027 0 0 1 24-24h416a24.027 24.027 0 0 1 24 24z"
81
+ id="path20"
82
+ style="fill:#800000" />
83
+ <path
84
+ d="m256 280a24 24 0 1 0 24 24 24.027 24.027 0 0 0 -24-24zm0 32a8 8 0 1 1 8-8 8.009 8.009 0 0 1 -8 8z"
85
+ id="path22"
86
+ style="fill:#800000" />
87
+ <path
88
+ d="m160 280a24 24 0 1 0 24 24 24.027 24.027 0 0 0 -24-24zm0 32a8 8 0 1 1 8-8 8.009 8.009 0 0 1 -8 8z"
89
+ id="path24"
90
+ style="fill:#800000" />
91
+ <path
92
+ d="m352 280a24 24 0 1 0 24 24 24.027 24.027 0 0 0 -24-24zm0 32a8 8 0 1 1 8-8 8.009 8.009 0 0 1 -8 8z"
93
+ id="path26"
94
+ style="fill:#800000" />
95
+ <path
96
+ d="m456 280a24 24 0 1 0 24 24 24.027 24.027 0 0 0 -24-24zm0 32a8 8 0 1 1 8-8 8.009 8.009 0 0 1 -8 8z"
97
+ id="path28"
98
+ style="fill:#800000" />
99
+ <path
100
+ d="m56 280a24 24 0 1 0 24 24 24.027 24.027 0 0 0 -24-24zm0 32a8 8 0 1 1 8-8 8.009 8.009 0 0 1 -8 8z"
101
+ id="path30"
102
+ style="fill:#800000" />
103
+ <path
104
+ d="m152 192h-80a8 8 0 0 0 0 16h80a8 8 0 0 0 0-16z"
105
+ id="path32"
106
+ style="fill:#800000" />
107
+ <path
108
+ d="m48 184h104a8 8 0 0 0 0-16h-104a8 8 0 0 0 0 16z"
109
+ id="path34"
110
+ style="fill:#800000" />
111
+ <path
112
+ d="m152 216h-24a8 8 0 0 0 0 16h24a8 8 0 0 0 0-16z"
113
+ id="path36"
114
+ style="fill:#800000" />
115
+ <path
116
+ d="m96 216a8 8 0 0 0 0 16h8a8 8 0 0 0 0-16z"
117
+ id="path38"
118
+ style="fill:#800000" />
119
+ </g>
120
+ </g>
121
+ </svg>
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tiny_conveyor/belt'
4
+ require 'tiny_conveyor/parcel'
5
+
6
+ # main file for Tiny Conveyor gem
7
+ module TinyConveyor
8
+ VERSION = '0.0.1'
9
+
10
+ class << self
11
+ # @return [Belt] newly created belt
12
+ def new
13
+ belt
14
+ end
15
+
16
+ # @param name [string] name of the task
17
+ # @param description [string] small description of the task
18
+ # @param action [Proc] action to run in separate thread
19
+ # @return [Array<Parcel>] pending parcels
20
+ def add_parcel(name, description, action)
21
+ belt.add_parcel(name, description, action)
22
+ end
23
+
24
+ # @param uuid [string] uuid of the parcel to remove
25
+ # @return [Array<Parcel>] pending parcels
26
+ def remove_parcel(uuid)
27
+ belt.remove_parcel_by_uuid(uuid)
28
+ end
29
+
30
+ def start_belt
31
+ belt.start_belt
32
+ end
33
+
34
+ # @return [boolean] true if the belt is running, false otherwhise
35
+ def running?
36
+ belt.running?
37
+ end
38
+
39
+ # @return [Array<Parcel>] pending parcels
40
+ def parcels
41
+ belt.parcels
42
+ end
43
+
44
+ # @return [Belt]
45
+ def belt
46
+ @belt ||= Belt.new
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TinyConveyor
4
+ # Thread manager, allow creation and execution of parcels
5
+ class Belt
6
+ require 'concurrent'
7
+ include Concurrent::Async
8
+ attr_reader :parcels
9
+
10
+ # @return [Belt] newly created belt
11
+ def initialize
12
+ super()
13
+ @parcels = []
14
+ @threads = []
15
+ @state = :waiting
16
+ end
17
+
18
+ # @param name [string] name of the task
19
+ # @param description [string] small description of the task
20
+ # @param action [Proc] action to run in separate thread
21
+ # @return [Array<Parcel>] pending parcels
22
+ def add_parcel(name, description, task)
23
+ parcel = Parcel.new(name, description, task)
24
+ @parcels << parcel
25
+ end
26
+
27
+ # @param uuid [string] uuid of the parcel to remove
28
+ # @return [Array<Parcel>] pending parcels
29
+ def remove_parcel_by_uuid(uuid)
30
+ parcel = @parcels.find { |p| p.uuid == uuid }
31
+ return @parcels if parcel.nil?
32
+
33
+ remove_parcel(parcel)
34
+ end
35
+
36
+ def start_belt
37
+ self.async.run_belt_entirely
38
+ end
39
+
40
+ def run_belt_entirely
41
+ execute until @parcels.empty?
42
+ end
43
+
44
+ # @return [boolean] true if the belt is running, false otherwhise
45
+ def running?
46
+ @state == :running
47
+ end
48
+
49
+ private
50
+
51
+ def remove_parcel(parcel)
52
+ new_parcels_array = @parcels.reject { |p| p == parcel }
53
+ @parcels = new_parcels_array
54
+ end
55
+
56
+ def execute
57
+ return true if running?
58
+
59
+ tasks = @parcels.clone
60
+ @state = :running
61
+ until tasks.empty?
62
+ current_parcel = tasks.shift
63
+ @parcels.first.start
64
+ current_parcel&.execute
65
+ @parcels.shift
66
+ end
67
+ @state = :waiting
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+ module TinyConveyor
5
+ # Encapsulate an action to run in a separated thread
6
+ class Parcel
7
+ attr_reader :name, :description, :state, :uuid
8
+
9
+ # @param name [string] name of the task
10
+ # @param description [string] small description of the task
11
+ # @param action [Proc] action to run in separate thread
12
+ # @return [Parcel] newly created parcel
13
+ def initialize(name, description, action)
14
+ @name = name
15
+ @description = description
16
+ @action = action
17
+ @state = :pending
18
+ @uuid = SecureRandom.uuid
19
+ end
20
+
21
+ def execute
22
+ @state = :running
23
+ @action.call
24
+ end
25
+
26
+ # @return [boolean] true if the parcel is executed, false otherwhise
27
+ def running?
28
+ @state == :running
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'tiny_conveyor'
7
+ s.version = '0.0.1'
8
+ s.required_ruby_version = '>= 2.0.0'
9
+ s.required_rubygems_version = '>= 1.8.11'
10
+ s.summary = 'Tiny wrapper aroung concurent ruby to create a queue of tasks'
11
+ s.authors = ['Flo Girardo']
12
+ s.email = 'florian@barbrousse.net'
13
+ s.files = `git ls-files`.split($RS).reject do |file|
14
+ file =~ %r{^spec/}
15
+ end
16
+ s.require_paths = ['lib']
17
+ s.homepage =
18
+ 'https://framagit.org/Radoteur/tiny-conveyor'
19
+ s.license = 'MIT'
20
+ s.add_dependency 'concurrent-ruby', '~> 1.1', '>= 1.1.5'
21
+ s.add_development_dependency('rspec', '~> 3')
22
+ s.add_development_dependency('yard', '~> 0.9')
23
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tiny_conveyor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Flo Girardo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: concurrent-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.1.5
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.1.5
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3'
47
+ - !ruby/object:Gem::Dependency
48
+ name: yard
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.9'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.9'
61
+ description:
62
+ email: florian@barbrousse.net
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - ".gitignore"
68
+ - ".rspec"
69
+ - Gemfile
70
+ - README.md
71
+ - doc/TinyConveyor.html
72
+ - doc/TinyConveyor/Belt.html
73
+ - doc/TinyConveyor/Parcel.html
74
+ - doc/_index.html
75
+ - doc/class_list.html
76
+ - doc/css/common.css
77
+ - doc/css/full_list.css
78
+ - doc/css/style.css
79
+ - doc/file.README.html
80
+ - doc/file_list.html
81
+ - doc/frames.html
82
+ - doc/index.html
83
+ - doc/js/app.js
84
+ - doc/js/full_list.js
85
+ - doc/js/jquery.js
86
+ - doc/method_list.html
87
+ - doc/top-level-namespace.html
88
+ - icon.png
89
+ - icon.svg
90
+ - lib/tiny_conveyor.rb
91
+ - lib/tiny_conveyor/belt.rb
92
+ - lib/tiny_conveyor/parcel.rb
93
+ - tiny_conveyor.gemspec
94
+ homepage: https://framagit.org/Radoteur/tiny-conveyor
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 2.0.0
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: 1.8.11
112
+ requirements: []
113
+ rubygems_version: 3.2.18
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Tiny wrapper aroung concurent ruby to create a queue of tasks
117
+ test_files: []