jobba 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/jobba/status.rb +4 -9
- data/lib/jobba/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f867ae880d3339b25e987267ac135429ee2fb80e
|
4
|
+
data.tar.gz: 3882b0e610200fe6b2c119dc46efe37261dea455
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 369cddf40dd02571641bd114043f8f70f74ba6b0803d191893a79f7375c40bfaa8114436fbabcbc95986d231491d4f86979af90564e8b284608f7cdad46b5553
|
7
|
+
data.tar.gz: 966e2fc051cd4d8c5f5c9a2abebb4286aa9960cfad46d77ca52bdbe06351bf92945963c1c3d7d0cf9694b3fe6b84ccfe7b0610cef169a125dbbfb1aaa251cbe4
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# jobba
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/jobba.svg)](http://badge.fury.io/rb/jobba)
|
3
4
|
[![Build Status](https://travis-ci.org/openstax/jobba.svg?branch=master)](https://travis-ci.org/openstax/jobba)
|
4
5
|
[![Code Climate](https://codeclimate.com/github/openstax/jobba/badges/gpa.svg)](https://codeclimate.com/github/openstax/jobba)
|
5
6
|
|
@@ -145,6 +146,8 @@ my_status.save({a: 'blah', b: [1,2,3]})
|
|
145
146
|
my_status.save("some string")
|
146
147
|
```
|
147
148
|
|
149
|
+
Note that if you `save` a hash with symbol keys it will be converted to string keys. In fact, any argument passed in to `save` will be converted to JSON and parsed back so that the `data` attribute returns the same thing regardless of if `data` is retrieved immediately after being set or after being loaded from Redis.
|
150
|
+
|
148
151
|
## Setting Job Name and Arguments
|
149
152
|
|
150
153
|
If you want to be able to query for all statuses for a certain kind of job, you can set the job's name in the status:
|
data/lib/jobba/status.rb
CHANGED
@@ -128,7 +128,8 @@ module Jobba
|
|
128
128
|
# end
|
129
129
|
|
130
130
|
def save(data)
|
131
|
-
|
131
|
+
normalized_data = JSON.parse(data.to_json, quirks_mode: true)
|
132
|
+
set(data: normalized_data)
|
132
133
|
end
|
133
134
|
|
134
135
|
def delete
|
@@ -193,16 +194,12 @@ module Jobba
|
|
193
194
|
|
194
195
|
@json_encoded_attrs = attrs[:raw]
|
195
196
|
|
196
|
-
if
|
197
|
-
@json_encoded_attrs['data'] ||= "{}"
|
198
|
-
@json_encoded_attrs['job_args'] ||= "{}"
|
199
|
-
else
|
197
|
+
if @json_encoded_attrs.nil? || @json_encoded_attrs.empty?
|
200
198
|
@id = attrs[:id] || attrs['id'] || SecureRandom.uuid
|
201
199
|
@state = attrs[:state] || attrs['state'] || State::UNKNOWN
|
202
200
|
@progress = attrs[:progress] || attrs['progress'] || 0
|
203
201
|
@errors = attrs[:errors] || attrs['errors'] || []
|
204
202
|
@data = attrs[:data] || attrs['data'] || {}
|
205
|
-
@job_args = OpenStruct.new # TODO need this and the above job args init?
|
206
203
|
|
207
204
|
if attrs[:persist]
|
208
205
|
redis.multi do
|
@@ -249,9 +246,7 @@ module Jobba
|
|
249
246
|
|
250
247
|
def set_hash_in_redis(hash)
|
251
248
|
redis_key_value_array =
|
252
|
-
hash.to_a
|
253
|
-
.collect{|kv_array| [kv_array[0], kv_array[1].to_json]}
|
254
|
-
.flatten(1)
|
249
|
+
hash.to_a.flat_map{|kv_array| [kv_array[0], kv_array[1].to_json]}
|
255
250
|
|
256
251
|
Jobba.redis.hmset(job_key, *redis_key_value_array)
|
257
252
|
end
|
data/lib/jobba/version.rb
CHANGED