transaction 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.MD +9 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +66 -2
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/lib/transaction/version.rb +3 -1
- data/lib/transaction.rb +1 -1
- data/transaction.gemspec +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b71218d59c5b76ff4673eeca6a60a22089ecf528f95eb9d659ad6e5abc657a1
|
4
|
+
data.tar.gz: 8746fa1b44166fc7e32293025a49b368935a20ca8b5d9bc95ede47e28bb29dda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f063c2251390d281fa403e59f286458c8384e91ebf5a6ec9f05b191f3e543d8e3aa45be97f746ec7cd351bc1d2401380394a2d24fe456cda0f8d2016abb5de0
|
7
|
+
data.tar.gz: c47ede5976c6586746364bb48c9417d3100210fe7995a994ff8edc8bc37a20e660f13118f226fa0636f0d230ebdbf03cc67e6da8b9657909eb546cd212332c2d
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.MD
CHANGED
@@ -4,7 +4,15 @@ 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.
|
7
|
+
## [0.1.5] - 2019-07-18
|
8
|
+
|
9
|
+
### Added
|
10
|
+
- Readme examples
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
- Transaction finished with default status `success`
|
14
|
+
|
15
|
+
## [0.1.4] - 2019-07-18
|
8
16
|
|
9
17
|
### Added
|
10
18
|
- Support for ruby >= 2.4
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,8 @@
|
|
7
7
|
|
8
8
|
# Transaction
|
9
9
|
|
10
|
-
Transaction is a small library to
|
10
|
+
Transaction is a small library which helps track status of running/upcoming tasks. These tasks can be a cron job, background jobs or a simple method. Any task can be plugged into a transaction block. Transaction uses redis to store the current status along with the additional attributes(provided during the initialization or transaction updation.)
|
11
|
+
|
11
12
|
To experiment with that code, run `bin/console` for an interactive prompt.
|
12
13
|
|
13
14
|
TODO: Delete this and the text above, and describe your gem
|
@@ -30,7 +31,70 @@ Or install it yourself as:
|
|
30
31
|
|
31
32
|
## Usage
|
32
33
|
|
33
|
-
|
34
|
+
### Ex 1: Simple transaction
|
35
|
+
```ruby
|
36
|
+
def sum_numbers
|
37
|
+
arr = (0...10_000).to_a
|
38
|
+
options = { created_at: Time.now, total: arr.count }
|
39
|
+
transaction = Transaction::Client.new(options: options)
|
40
|
+
|
41
|
+
transaction.start!
|
42
|
+
puts transaction.status # Status moves from `queued` to `processing`
|
43
|
+
|
44
|
+
count = 0
|
45
|
+
(1..10_000).each do |i|
|
46
|
+
# do some other stuff
|
47
|
+
transaction.update_attributes(count: count += 1)
|
48
|
+
# do some other stuff
|
49
|
+
end
|
50
|
+
|
51
|
+
transaction.finish! # By default moves to status 'success'.
|
52
|
+
|
53
|
+
puts transaction.status # 'success'
|
54
|
+
puts transaction.attributes # {:status=>:success, :created_at=>2019-07-19 06:06:43 +0530, :total=>10000, :count=>10000}
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
### Ex 2: Initialize or find a transaction with a transaction id.
|
59
|
+
```ruby
|
60
|
+
def task1
|
61
|
+
transaction = Transaction::Client.new
|
62
|
+
SomeWorkerJob.perform_later(transaction.transaction_id) # sidekiq or resque
|
63
|
+
end
|
64
|
+
|
65
|
+
class SomeWorkerJob < ApplicationJob
|
66
|
+
queue_as :default
|
67
|
+
|
68
|
+
def perform transaction_id
|
69
|
+
tr = Transaction::Client.new(transaction_id: transaction_id) # intialize with given transaction_id
|
70
|
+
tr.start!
|
71
|
+
|
72
|
+
# do a bunch of stuff
|
73
|
+
tr.finish!
|
74
|
+
end
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
### Keeping transactions in sync.
|
79
|
+
Let's say we have 2 transactions `t1` and `t2` both initialized with same transaction id. If `t2` updates the transaction, then `t1` can simple refresh the transaction to get in sync with `t2`. Note: the transaction will be refreshed with the most recent values. (Versioning transaction updates ??? => Woah that's a nice PR idea.)
|
80
|
+
```ruby
|
81
|
+
def task1
|
82
|
+
transaction = Transaction::Client.new
|
83
|
+
transaction.start!
|
84
|
+
task2(transaction.transaction_id)
|
85
|
+
sleep(5) # just letting task 2 finish.
|
86
|
+
|
87
|
+
puts transaction.status # 'processing'
|
88
|
+
transaction.refresh!
|
89
|
+
puts transaction.status # 'error'
|
90
|
+
end
|
91
|
+
|
92
|
+
def task2 transaction_id # in some other context altogether. Task 2 is not at all related to task 1.
|
93
|
+
transaction = Transaction::Client.new(transaction_id: transaction_id)
|
94
|
+
# do some stuff
|
95
|
+
transaction.finish!('error')
|
96
|
+
end
|
97
|
+
```
|
34
98
|
|
35
99
|
## Development
|
36
100
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/lib/transaction/version.rb
CHANGED
data/lib/transaction.rb
CHANGED
data/transaction.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anurag Tiwari
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|