orbitalqueue 0.0.1 → 0.0.2
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/README.md +10 -3
- data/lib/orbitalqueue.rb +42 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d331ea29dd6bc80aa3c1127749f782845d1f23c2a9729f987af9128f1922bf21
|
4
|
+
data.tar.gz: 5f7c04a0cef45399d4726900330ac96b1714e3275545a2d1e4e209fe61aec6c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7d5ead3e5494a3f38808e9b363b1ceb624168e294ee6a7165630092ec3ff3a58448234f434411f865539e89d8aa5f1cdf3100adde94ca6cc26066ec5c1d0795
|
7
|
+
data.tar.gz: 7aab8b14af6f147b0b7276e37baee3db4324ca4052445c1fefcdd094f47e64e770f0a3357eec8a69d35ebbedd2263b7b3b5d208e457c73b5f6b3f34a5560ba39
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Orbital Queue
|
2
2
|
|
3
3
|
[](https://github.com/reasonset/orbital-queue/actions/workflows/ci.yml)
|
4
4
|
|
@@ -39,11 +39,12 @@ Since enqueued objects are serialized using `Marshal` and persisted as files, ca
|
|
39
39
|
require 'orbitalqueue'
|
40
40
|
|
41
41
|
queue = OrbitalQueue.new("/path/to/queue")
|
42
|
-
|
42
|
+
item = queue.pop
|
43
|
+
data = item.data
|
43
44
|
|
44
45
|
# Something, something...
|
45
46
|
|
46
|
-
|
47
|
+
item.complete
|
47
48
|
```
|
48
49
|
|
49
50
|
Calling `#pop` retrieves a single item from the queue in no particular order.
|
@@ -54,3 +55,9 @@ If guaranteed completion is not required and the item should be removed immediat
|
|
54
55
|
|
55
56
|
Both `#pop` and `#pop!` return a queue item as a `Hash`. If the original object was not a `Hash`, it will be stored under the `:data` key. Regardless of the original type, the queue ID is always stored under the `:queue_id` key.
|
56
57
|
|
58
|
+
# About Orbital Design
|
59
|
+
|
60
|
+
## Description
|
61
|
+
|
62
|
+
## Design pattern rules
|
63
|
+
|
data/lib/orbitalqueue.rb
CHANGED
@@ -45,6 +45,8 @@ class OrbitalQueue
|
|
45
45
|
|
46
46
|
# Pop data from queue.
|
47
47
|
# Popped queue items are placed in the checkout directory. After processing is complete, +#complete+ must be called to remove the item from the queue.
|
48
|
+
#
|
49
|
+
# If block is given, complete automatically after yield.
|
48
50
|
def pop
|
49
51
|
queue_data = nil
|
50
52
|
queue_id = nil
|
@@ -57,28 +59,29 @@ class OrbitalQueue
|
|
57
59
|
next
|
58
60
|
end
|
59
61
|
|
60
|
-
|
62
|
+
data = Marshal.load(File.read File.join(@queue_dir, ".checkout", File.basename(qf)))
|
61
63
|
queue_id = File.basename qf, ".marshal"
|
62
64
|
|
63
|
-
|
64
|
-
queue_data[:queue_id] = queue_id
|
65
|
-
else
|
66
|
-
queue_data = {queue_id: queue_id, data: queue_data}
|
67
|
-
end
|
65
|
+
queue_data = OrbitalQueue::QueueObject.new(self, data, queue_id)
|
68
66
|
break
|
69
67
|
end
|
70
68
|
|
71
|
-
|
69
|
+
if block_given?
|
70
|
+
yield queue_data.data
|
71
|
+
complete queue_id
|
72
|
+
else
|
73
|
+
queue_data
|
74
|
+
end
|
72
75
|
end
|
73
76
|
|
74
77
|
# Pop data from queue and remove it from queue.
|
75
78
|
def pop!
|
76
|
-
|
77
|
-
if
|
78
|
-
complete
|
79
|
+
queue_item = pop
|
80
|
+
if queue_item
|
81
|
+
queue_item.complete
|
79
82
|
end
|
80
83
|
|
81
|
-
|
84
|
+
queue_item
|
82
85
|
end
|
83
86
|
|
84
87
|
# Remove checked out queue item.
|
@@ -92,3 +95,31 @@ class OrbitalQueue
|
|
92
95
|
queue_id
|
93
96
|
end
|
94
97
|
end
|
98
|
+
|
99
|
+
# Queue item capsule.
|
100
|
+
class OrbitalQueue::QueueObject
|
101
|
+
def initialize(queue, data, queue_id)
|
102
|
+
@queue = queue
|
103
|
+
@data = data
|
104
|
+
@queue_id = queue_id
|
105
|
+
@completed = false
|
106
|
+
end
|
107
|
+
|
108
|
+
attr_reader :data
|
109
|
+
|
110
|
+
# Another complete interface.
|
111
|
+
def complete
|
112
|
+
if @completed
|
113
|
+
nil
|
114
|
+
else
|
115
|
+
@queue.complete(@queue_id)
|
116
|
+
@completed = true
|
117
|
+
@queue_id
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# Terrible redundunt method.
|
122
|
+
def complete?
|
123
|
+
@completed
|
124
|
+
end
|
125
|
+
end
|