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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4675dda1fefb98498db0d38281ab7a1507266cb0143007152fe38c2855c7d5b
4
- data.tar.gz: d92d587dfb5916d70a0f23d464201f1171dc70fb26bdc7abad3cf1fb9d6a6a53
3
+ metadata.gz: 4b71218d59c5b76ff4673eeca6a60a22089ecf528f95eb9d659ad6e5abc657a1
4
+ data.tar.gz: 8746fa1b44166fc7e32293025a49b368935a20ca8b5d9bc95ede47e28bb29dda
5
5
  SHA512:
6
- metadata.gz: 33227c6f7ccc54c6e4fc83067246b3c73b66ecc8d339b1ab43325e1ed4e710136478a1d61dc0ebef0143c91bcfc4fe5172736153091246f2e366d855a0a96f0d
7
- data.tar.gz: 445d685de0a0addbf28a2df35ef225ad8ed3b2c29d2296c37edee5ca3145417b9efb762a88b908c5cca8d215dfb83c60437e71001037d723527ba1a9b20290db
6
+ metadata.gz: 6f063c2251390d281fa403e59f286458c8384e91ebf5a6ec9f05b191f3e543d8e3aa45be97f746ec7cd351bc1d2401380394a2d24fe456cda0f8d2016abb5de0
7
+ data.tar.gz: c47ede5976c6586746364bb48c9417d3100210fe7995a994ff8edc8bc37a20e660f13118f226fa0636f0d230ebdbf03cc67e6da8b9657909eb546cd212332c2d
data/.rubocop.yml CHANGED
@@ -1 +1,5 @@
1
1
  inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ DisabledByDefault: false
5
+ TargetRubyVersion: 2.4.0
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.4] - 2019-07-19
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in transaction.gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- transaction (0.1.4)
4
+ transaction (0.1.5)
5
5
  redis (>= 4.0.2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -7,7 +7,8 @@
7
7
 
8
8
  # Transaction
9
9
 
10
- Transaction is a small library to help you out with tracking the progress of your long running tasks.
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
- TODO: Write usage instructions here
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'transaction'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Transaction
2
- VERSION = '0.1.4'.freeze
4
+ VERSION = '0.1.5'
3
5
  end
data/lib/transaction.rb CHANGED
@@ -60,7 +60,7 @@ module Transaction
60
60
  update_status(:processing)
61
61
  end
62
62
 
63
- def finish!(status, clear = false)
63
+ def finish!(status = 'success', clear = false)
64
64
  update_status(status)
65
65
 
66
66
  redis_delete if clear
data/transaction.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'transaction/version'
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
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-18 00:00:00.000000000 Z
11
+ date: 2019-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis