laboristo 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -12
- data/bin/laboristo +3 -16
- data/laboristo.gemspec +2 -1
- data/lib/laboristo.rb +2 -11
- data/test/queue_test.rb +6 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a984e5e708ac9e7852e539987cf0b68bb9e04cdc
|
4
|
+
data.tar.gz: 8238919ff0403e16c718d2551c6014f382100957
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0085a639eec84750f0df83f60a35d0803c9d3a43217cd938efe727109e1db5947314dd23119d3dc69cbab90b01ef936444b53545a4d856f464e2ce1a6e245e6
|
7
|
+
data.tar.gz: 6f3e20625c09b0901775db9620e2d17dbcadbfd57c6da2588c348a73bdb599d3b4543e9ffc228a61b6a446253fbbcdc2c83964f6f33ce3df7e1c883afc0c22b8
|
data/README.md
CHANGED
@@ -38,8 +38,6 @@ And then execute:
|
|
38
38
|
|
39
39
|
Before using Laboristo, you will need to set some environment variables:
|
40
40
|
|
41
|
-
AWS_REGION=<your_aws_region>
|
42
|
-
AWS_ACCOUNT_ID=<your_aws_account_id>
|
43
41
|
AWS_ACCESS_KEY_ID=<your_aws_access_key>
|
44
42
|
AWS_SECRET_ACCESS_KEY=<your_aws_secret_key>
|
45
43
|
|
@@ -57,18 +55,24 @@ Here are some considerations that you need to know when using Laboristo and SQS:
|
|
57
55
|
|
58
56
|
## Usage
|
59
57
|
|
58
|
+
To refer to a particular queue, you will need the corresponding queue url, an attribute defined by AWS SQS when you create a queue. You can check the queue url in the AWS SQS Console. In the following examples, we will assume a queue having an url like this:
|
59
|
+
|
60
|
+
```
|
61
|
+
https://sqs.us-east-1.amazonaws.com/123456789/my_queue
|
62
|
+
```
|
63
|
+
|
60
64
|
To push a message to the queue:
|
61
65
|
|
62
66
|
```ruby
|
63
67
|
require 'laboristo'
|
64
68
|
|
65
|
-
Laboristo['my_queue'] << 'some message'
|
69
|
+
Laboristo['https://sqs.us-east-1.amazonaws.com/123456789/my_queue'] << 'some message'
|
66
70
|
```
|
67
71
|
|
68
72
|
And get messages from a queue:
|
69
73
|
```ruby
|
70
74
|
require 'laboristo'
|
71
|
-
Laboristo['my_queue'].each do |msg|
|
75
|
+
Laboristo['https://sqs.us-east-1.amazonaws.com/123456789/my_queue'].each do |msg|
|
72
76
|
# Do something with msg...
|
73
77
|
end
|
74
78
|
```
|
@@ -80,24 +84,30 @@ Workers can be as simple as this:
|
|
80
84
|
```ruby
|
81
85
|
require 'my_app'
|
82
86
|
|
83
|
-
Laboristo['my_queue'].each do |message|
|
87
|
+
Laboristo['https://sqs.us-east-1.amazonaws.com/123456789/my_queue'].each do |message|
|
84
88
|
# Do some magic stuff with the message
|
85
89
|
end
|
86
90
|
```
|
87
91
|
|
88
|
-
|
92
|
+
For instance, you can place your worker at ```./workers/my_worker.rb``` and run this code to run worker in foreground:
|
89
93
|
|
90
94
|
```
|
91
|
-
$ laboristo my_worker
|
95
|
+
$ laboristo workers/my_worker
|
92
96
|
```
|
93
97
|
|
94
98
|
To run it in background you can use ```-d``` flag to daemonize the process:
|
95
99
|
|
96
100
|
```
|
97
|
-
$ laboristo my_worker -d
|
101
|
+
$ laboristo workers/my_worker -d
|
102
|
+
```
|
103
|
+
|
104
|
+
And, to stop a worker running in background, you can confidently kill the process:
|
105
|
+
|
106
|
+
```
|
107
|
+
$ kill $$(cat /tmp/my_worker.pid)
|
98
108
|
```
|
99
109
|
|
100
|
-
|
110
|
+
Keep in mind that, because of how SQS works, unprocessed messages will go back to the queue. So, if you kill the worker process, unprocessed messages will go back to queue.
|
101
111
|
|
102
112
|
### Purging
|
103
113
|
|
@@ -107,6 +117,8 @@ Delete all messages from a queue:
|
|
107
117
|
Laboristo['my_queue'].purge
|
108
118
|
```
|
109
119
|
|
120
|
+
Because of AWS SQS restrictions, you can purge a queue only once every 60 seconds.
|
121
|
+
|
110
122
|
## Development
|
111
123
|
|
112
124
|
After cloning repository install dependencies using [dep](https://github.com/cyx/dep):
|
@@ -123,9 +135,7 @@ Set environment variables as explained before in this document, and run the test
|
|
123
135
|
|
124
136
|
### TO-DO:
|
125
137
|
|
126
|
-
First of all,
|
127
|
-
|
128
|
-
In future versions, I'd like to improve the worker bin so that it can be started/stopped in a more elegant fashion than simply killing the process ;-)
|
138
|
+
First of all, help me adding more tests! This gem stated as an experiment, so you can expect bugs.
|
129
139
|
|
130
140
|
Feel free to report bugs, open issues, comments and pull requests. Only keep in mind that I just want to keep this gem neat and simple.
|
131
141
|
|
data/bin/laboristo
CHANGED
@@ -1,20 +1,8 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
|
3
|
-
stop = proc do
|
4
|
-
if defined?(Laboristo)
|
5
|
-
Laboristo.stop
|
6
|
-
else
|
7
|
-
exit 0
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
trap(:INT, &stop)
|
12
|
-
trap(:TERM, &stop)
|
13
|
-
|
14
3
|
usage = <<-EOS
|
15
4
|
Usage:
|
16
|
-
laboristo
|
17
|
-
laboristo stop <worker>
|
5
|
+
laboristo <worker> [-d|--daemonize]
|
18
6
|
EOS
|
19
7
|
|
20
8
|
require 'clap'
|
@@ -31,10 +19,9 @@ args = Clap.run ARGV,
|
|
31
19
|
exit 0
|
32
20
|
}
|
33
21
|
|
34
|
-
command = args.shift
|
35
22
|
worker = args.shift
|
36
|
-
worker_path = File.expand_path(
|
37
|
-
pid_path = File.expand_path("tmp/#{worker}.pid")
|
23
|
+
worker_path = File.expand_path(worker)
|
24
|
+
pid_path = File.expand_path("/tmp/#{worker}.pid")
|
38
25
|
|
39
26
|
$stdout.sync = true
|
40
27
|
|
data/laboristo.gemspec
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'laboristo'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.4.0'
|
4
4
|
s.summary = 'Simple messages and workers for AWS SQS'
|
5
|
+
s.description = 'A very simple way to handle messages and workers using AWS SQS'
|
5
6
|
s.authors = ['matiasow']
|
6
7
|
s.email = ['matiasow@gmail.com']
|
7
8
|
s.homepage = 'https://github.com/matiasow/laboristo'
|
data/lib/laboristo.rb
CHANGED
@@ -3,15 +3,12 @@ require 'base64'
|
|
3
3
|
|
4
4
|
module Laboristo
|
5
5
|
class Queue
|
6
|
-
attr_accessor :name
|
7
6
|
attr_accessor :url
|
8
7
|
attr_accessor :sqs
|
9
8
|
|
10
|
-
def initialize(
|
11
|
-
@name = name
|
9
|
+
def initialize(url)
|
12
10
|
@sqs = Aws::SQS::Client.new
|
13
|
-
@url =
|
14
|
-
@stopping = false
|
11
|
+
@url = url
|
15
12
|
end
|
16
13
|
|
17
14
|
def push(message)
|
@@ -34,18 +31,12 @@ module Laboristo
|
|
34
31
|
$stdout.puts "ERROR: Can't process message #{msg[:message_id]}.\n#{e}"
|
35
32
|
end
|
36
33
|
end
|
37
|
-
|
38
|
-
break if @stopping
|
39
34
|
end
|
40
35
|
end
|
41
36
|
|
42
37
|
alias << push
|
43
38
|
alias pop each
|
44
39
|
|
45
|
-
def stop
|
46
|
-
@stopping = true
|
47
|
-
end
|
48
|
-
|
49
40
|
def purge
|
50
41
|
@sqs.purge_queue(queue_url: @url)
|
51
42
|
end
|
data/test/queue_test.rb
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
require_relative 'helper'
|
2
2
|
|
3
3
|
test 'initialize' do
|
4
|
-
q = Laboristo::Queue.new(@
|
5
|
-
assert q.name == @queue_name
|
4
|
+
q = Laboristo::Queue.new(@url)
|
6
5
|
assert q.sqs.is_a? Aws::SQS::Client
|
7
6
|
assert q.url == @url
|
8
7
|
end
|
9
8
|
|
10
9
|
test 'initialize through []' do
|
11
|
-
q = Laboristo[@
|
12
|
-
assert q.name == @queue_name
|
10
|
+
q = Laboristo[@url]
|
13
11
|
assert q.sqs.is_a? Aws::SQS::Client
|
14
12
|
assert q.url == @url
|
15
13
|
end
|
16
14
|
|
17
15
|
test 'push message to queue' do
|
18
|
-
q = Laboristo[@
|
16
|
+
q = Laboristo[@url]
|
19
17
|
msg = SecureRandom.uuid
|
20
18
|
|
21
19
|
q.push(msg)
|
@@ -27,7 +25,7 @@ test 'push message to queue' do
|
|
27
25
|
end
|
28
26
|
|
29
27
|
test 'push message to queue using <<' do
|
30
|
-
q = Laboristo[@
|
28
|
+
q = Laboristo[@url]
|
31
29
|
msg = SecureRandom.uuid
|
32
30
|
|
33
31
|
q << msg
|
@@ -39,7 +37,7 @@ test 'push message to queue using <<' do
|
|
39
37
|
end
|
40
38
|
|
41
39
|
test 'fetch messages using pop' do
|
42
|
-
q = Laboristo[@
|
40
|
+
q = Laboristo[@url]
|
43
41
|
msg = SecureRandom.uuid
|
44
42
|
|
45
43
|
send_message(msg)
|
@@ -51,7 +49,7 @@ test 'fetch messages using pop' do
|
|
51
49
|
end
|
52
50
|
|
53
51
|
test 'fetch messages using each' do
|
54
|
-
q = Laboristo[@
|
52
|
+
q = Laboristo[@url]
|
55
53
|
msg = SecureRandom.uuid
|
56
54
|
|
57
55
|
send_message(msg)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: laboristo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- matiasow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-core
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.2'
|
55
|
-
description:
|
55
|
+
description: A very simple way to handle messages and workers using AWS SQS
|
56
56
|
email:
|
57
57
|
- matiasow@gmail.com
|
58
58
|
executables:
|