transaction 0.1.5 → 0.1.6.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.MD +12 -1
- data/Gemfile.lock +1 -1
- data/README.md +22 -1
- data/lib/transaction/version.rb +1 -1
- data/lib/transaction.rb +7 -1
- data/transaction.gemspec +2 -2
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e3a97b6b934b5b7677f0fa30f41fed6b04f4e4f0d81097fd2661be8fba4c308
|
4
|
+
data.tar.gz: fce86fde3e3927644cb28758c51e544b34b7c29b8916d40133a23854d5a50cd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0e609d2c58f1d8ec03fe5941a8928e5d1e27460be6f3d8b5268f01c3c8c36b26f3c62e2350d02b74d6dc83d1063a2ca67df93a3edf205231cea1fbb9b885a29
|
7
|
+
data.tar.gz: 8a9ca121c4c728eb1937020a587012b08354793f1b06db12d188876d937a22582ae744a30183e93cc39ca3090fe8633e400c702c508e1c53d01ddab8a259941f
|
data/CHANGELOG.MD
CHANGED
@@ -4,7 +4,18 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
-
## [0.1.5] - 2019-07-
|
7
|
+
## [0.1.5] - 2019-07-19
|
8
|
+
|
9
|
+
### Added
|
10
|
+
- specs for update_attributes
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
- Raise ArgumentError if invalid attributes are passed in `update_attributes`
|
14
|
+
- Raise StandardError if transaction has expired.
|
15
|
+
- specs for `refresh!`
|
16
|
+
|
17
|
+
|
18
|
+
## [0.1.5] - 2019-07-19
|
8
19
|
|
9
20
|
### Added
|
10
21
|
- Readme examples
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,6 @@ Transaction is a small library which helps track status of running/upcoming task
|
|
11
11
|
|
12
12
|
To experiment with that code, run `bin/console` for an interactive prompt.
|
13
13
|
|
14
|
-
TODO: Delete this and the text above, and describe your gem
|
15
14
|
|
16
15
|
## Installation
|
17
16
|
|
@@ -31,6 +30,28 @@ Or install it yourself as:
|
|
31
30
|
|
32
31
|
## Usage
|
33
32
|
|
33
|
+
### Initializing a transaction
|
34
|
+
A transaction can be newly initialized or be found with the given transaction_id. If no transaction is found then a new transaction in created.
|
35
|
+
```ruby
|
36
|
+
attributes = {created_at: Time.now, count: 0 }
|
37
|
+
transaction = Transaction::Client.new(options: attributes) # creates a new instance of transaction
|
38
|
+
transaction1 = Transaction::Client.new(transaction_id: transaction.transaction_id) # finds the transaction.
|
39
|
+
```
|
40
|
+
|
41
|
+
### Accepted methods for a transaction
|
42
|
+
The default status of any new transaction is **`queued`**.
|
43
|
+
Accepted statuses: **['queued', 'processing', 'success', 'error']**. Any transaction at any point will be in one of the states.
|
44
|
+
|
45
|
+
method | params | description
|
46
|
+
|:-:|---|---
|
47
|
+
start! | - | moves to status `processing` from `queued`.
|
48
|
+
finish! | (status='success', clear=false) | moves to the passed status (default: `success`). `clear = true` destroys the entry from redis cache.
|
49
|
+
clear! | - | destroys the current entry from redis cache.
|
50
|
+
refresh! | - | sync current instance transaction with latest cache (Other instance of transaction initiated with same transaction id can update the attributes. Hence `refresh!` is required.).
|
51
|
+
update_status | status | moves to the passed status. Raises `'Invalid Status'` error if status is not in one of the **Accepted statuses** defined above.
|
52
|
+
update_attributes | options = {} | merges the passed options hash to the current attributes object. Raises `ArgumentError` if invalid type is passed in options.
|
53
|
+
|
54
|
+
|
34
55
|
### Ex 1: Simple transaction
|
35
56
|
```ruby
|
36
57
|
def sum_numbers
|
data/lib/transaction/version.rb
CHANGED
data/lib/transaction.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'transaction/version'
|
2
4
|
require 'securerandom'
|
3
5
|
require 'redis'
|
@@ -44,6 +46,10 @@ module Transaction
|
|
44
46
|
end
|
45
47
|
|
46
48
|
def update_attributes(options)
|
49
|
+
unless options.is_a? Hash
|
50
|
+
raise ArgumentError, 'Invalid type. Expected Hash'
|
51
|
+
end
|
52
|
+
|
47
53
|
@attributes = symbolize_keys!(@attributes.merge!(options))
|
48
54
|
redis_set(@transaction_id, @attributes.to_json)
|
49
55
|
@status = @attributes[:status].to_s
|
@@ -73,7 +79,7 @@ module Transaction
|
|
73
79
|
|
74
80
|
def refresh!
|
75
81
|
@attributes = parsed_attributes
|
76
|
-
raise 'Transaction expired' if @attributes.nil?
|
82
|
+
raise StandardError, 'Transaction expired' if @attributes.nil?
|
77
83
|
|
78
84
|
@status = @attributes[:status].to_s
|
79
85
|
end
|
data/transaction.gemspec
CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ['Anurag Tiwari']
|
11
11
|
spec.email = ['tiwari.anurag126@gmail.com']
|
12
12
|
|
13
|
-
spec.summary = '
|
14
|
-
spec.description = '
|
13
|
+
spec.summary = 'Manage transaction lifecycle - save/update status and information about the transaction.'
|
14
|
+
spec.description = 'A transaction can be a simple method or a long background process. Managing transactions is difficult especially when information about the transaction is of importance. This library helps you manage information relevant to the transaction. Current status and additional info about the task is stored is stored in redis datastore. This information can be retrieved at any point of time until the transaction is expired.'
|
15
15
|
spec.homepage = 'https://github.com/t2013anurag/transaction'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anurag Tiwari
|
@@ -80,7 +80,12 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description: A transaction can be a simple method or a long background process. Managing
|
84
|
+
transactions is difficult especially when information about the transaction is of
|
85
|
+
importance. This library helps you manage information relevant to the transaction.
|
86
|
+
Current status and additional info about the task is stored is stored in redis datastore.
|
87
|
+
This information can be retrieved at any point of time until the transaction is
|
88
|
+
expired.
|
84
89
|
email:
|
85
90
|
- tiwari.anurag126@gmail.com
|
86
91
|
executables: []
|
@@ -120,13 +125,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
125
|
version: 2.4.0
|
121
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
127
|
requirements:
|
123
|
-
- - "
|
128
|
+
- - ">"
|
124
129
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
130
|
+
version: 1.3.1
|
126
131
|
requirements: []
|
127
132
|
rubyforge_project:
|
128
133
|
rubygems_version: 2.7.6
|
129
134
|
signing_key:
|
130
135
|
specification_version: 4
|
131
|
-
summary:
|
136
|
+
summary: Manage transaction lifecycle - save/update status and information about the
|
137
|
+
transaction.
|
132
138
|
test_files: []
|