tiny_work_service 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/tiny_work_service.rb +52 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: af9afaca880e9be9ef717b24166a7c3670119bdd35cc58084edad8271da94e80
|
4
|
+
data.tar.gz: 60a483d580dd54c88a584109620b40e1d728225b2229c5dfaa84806da8eb1e36
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1658d413a33e68eda21894c65e834d51352a2ca012183b6f1646f6b322d4f6c5c592f8b06f28ab4f9d89171088b60ba1592ede2d74e8eb5bbe50dd56e75bf0d5
|
7
|
+
data.tar.gz: 5cf7b2dd07e0ebdf0f96252cdef13215faaf28e6c07167dfad03b7231487d4e956704c01c468391472b8b69df5fe786da4665035a492e698c1afe5d3fe376d24
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'tiny_tcp_service'
|
2
|
+
|
3
|
+
# usage:
|
4
|
+
# s = TinyWorkService.new(1234)
|
5
|
+
# s.stop!
|
6
|
+
class TinyWorkService
|
7
|
+
def initialize(port)
|
8
|
+
@service = TinyTCPService.new(port)
|
9
|
+
@service.msg_handler = self
|
10
|
+
@jobs = Queue.new
|
11
|
+
|
12
|
+
Thread.new do
|
13
|
+
loop do
|
14
|
+
break unless @service.running?
|
15
|
+
|
16
|
+
print "\rTinyWorkService #{@jobs.length.to_s.rjust(6)} jobs #{@service.num_clients.to_s.rjust(4)} workers\e[K"
|
17
|
+
sleep 0.5
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# interface for TinyTCPService
|
23
|
+
def call(m)
|
24
|
+
raise TinyTCPService::BadClient.new("nil message") if m.nil?
|
25
|
+
|
26
|
+
case
|
27
|
+
when m[0] == '+' # add a job to the queue
|
28
|
+
self << m[1..]
|
29
|
+
'ok' # ok, job received
|
30
|
+
when m[0] == '-' # take a job from the queue
|
31
|
+
shift || ''
|
32
|
+
else
|
33
|
+
raise TinyTCPService::BadClient.new("Client sent invalid message: `#{m[..50]}'")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# enqueue a job
|
38
|
+
def <<(j)
|
39
|
+
@jobs << j
|
40
|
+
end
|
41
|
+
|
42
|
+
# return the first job in the work queue, if there is one present
|
43
|
+
# otherwise, return nil
|
44
|
+
def shift
|
45
|
+
return nil if @jobs.empty?
|
46
|
+
@jobs.shift
|
47
|
+
end
|
48
|
+
|
49
|
+
def stop!
|
50
|
+
@service.stop!
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tiny_work_service
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Lunt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: tiny_tcp_service
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: uses the tiny_tcp_service gem to implement a job queue
|
28
|
+
email: jefflunt@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/tiny_work_service.rb
|
34
|
+
homepage: https://github.com/jefflunt/tiny_work_service
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubygems_version: 3.3.7
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: uses the tiny_tcp_service gem to implement a job queue
|
57
|
+
test_files: []
|