conflow 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 736a50603837a0bd935229a07df384630c29f16d5d796e9d91ab9dc97c163d98
4
+ data.tar.gz: 579a36c20e8b42a68657eafc9632725a3108bf5b9eeaab70f391f43629dedb01
5
+ SHA512:
6
+ metadata.gz: f850accd201ad219d809d45b874440d4c9aeff54400289bfcb7443ea9281eb240c52402a7ef38d1afaef56b7255776d763f011f3e06642f36c1b60cecbeec023
7
+ data.tar.gz: 284ce027afa093cb9fb6e6f8389e9bf71cd966a801dc8c3407f32ad94b0596bcca7f864b78f7e40760b6afa28f889e8ce636719a9dce6d232045ce219dcf7f10
data/.codeclimate.yml ADDED
@@ -0,0 +1,6 @@
1
+ version: "2"
2
+ plugins:
3
+ rubocop:
4
+ enabled: true
5
+ bundler-audit:
6
+ enabled: true
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,19 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+
4
+ Metrics/LineLength:
5
+ Max: 125
6
+
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ - "spec/**/*.rb"
10
+
11
+ StringLiterals:
12
+ EnforcedStyle: double_quotes
13
+
14
+ DotPosition:
15
+ EnforcedStyle: leading
16
+
17
+ Naming/PredicateName:
18
+ NameWhitelist:
19
+ - has_many
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ services:
5
+ - redis-server
6
+ rvm:
7
+ - 2.3.6
8
+ - 2.4.3
9
+ - 2.5.0
10
+ before_install: gem install bundler -v 1.16.1
11
+ before_script:
12
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
13
+ - chmod +x ./cc-test-reporter
14
+ - ./cc-test-reporter before-build
15
+ script: bundle exec rspec
16
+ after_script:
17
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.1.0
2
+
3
+ - First release! :pizza:
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at michal.begejowicz@codesthq.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in conflow.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ conflow (0.1.0)
5
+ redis (~> 4.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.0)
11
+ coderay (1.1.2)
12
+ connection_pool (2.2.1)
13
+ diff-lcs (1.3)
14
+ docile (1.1.5)
15
+ json (2.1.0)
16
+ method_source (0.9.0)
17
+ parallel (1.12.1)
18
+ parser (2.5.0.3)
19
+ ast (~> 2.4.0)
20
+ powerpack (0.1.1)
21
+ pry (0.11.3)
22
+ coderay (~> 1.1.0)
23
+ method_source (~> 0.9.0)
24
+ rainbow (3.0.0)
25
+ rake (12.3.0)
26
+ redis (4.0.1)
27
+ rspec (3.7.0)
28
+ rspec-core (~> 3.7.0)
29
+ rspec-expectations (~> 3.7.0)
30
+ rspec-mocks (~> 3.7.0)
31
+ rspec-core (3.7.1)
32
+ rspec-support (~> 3.7.0)
33
+ rspec-expectations (3.7.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.7.0)
36
+ rspec-mocks (3.7.0)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.7.0)
39
+ rspec-support (3.7.1)
40
+ rubocop (0.53.0)
41
+ parallel (~> 1.10)
42
+ parser (>= 2.5)
43
+ powerpack (~> 0.1)
44
+ rainbow (>= 2.2.2, < 4.0)
45
+ ruby-progressbar (~> 1.7)
46
+ unicode-display_width (~> 1.0, >= 1.0.1)
47
+ ruby-progressbar (1.9.0)
48
+ simplecov (0.15.1)
49
+ docile (~> 1.1.0)
50
+ json (>= 1.8, < 3)
51
+ simplecov-html (~> 0.10.0)
52
+ simplecov-html (0.10.2)
53
+ unicode-display_width (1.3.0)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ bundler (~> 1.16)
60
+ conflow!
61
+ connection_pool (~> 2.2)
62
+ pry (~> 0.11)
63
+ rake (~> 12.0)
64
+ rspec (~> 3.0)
65
+ rubocop (~> 0.51)
66
+ simplecov (~> 0.15)
67
+
68
+ BUNDLED WITH
69
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Michał Begejowicz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # Conflow
2
+
3
+ [![Build Status](https://travis-ci.org/fanfilmu/conflow.svg?branch=master)](https://travis-ci.org/fanfilmu/conflow) [![Maintainability](https://api.codeclimate.com/v1/badges/80b66a285ca1803f391a/maintainability)](https://codeclimate.com/github/fanfilmu/conflow/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/80b66a285ca1803f391a/test_coverage)](https://codeclimate.com/github/fanfilmu/conflow/test_coverage)
4
+
5
+ Conflow allows defining comlicated workflows with dependencies. Inspired by [Gush](https://github.com/chaps-io/gush) (the idea) and [Redis::Objects](https://github.com/nateware/redis-objects) (the implementation) it focuses solely on dependency logic, while leaving queueing jobs and executing them entirely in hands of the programmer.
6
+
7
+ Please have a look at `Gush` if you already use Rails and ActiveJob - it might suit your needs better.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem "conflow"
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install conflow
24
+
25
+ ## Usage
26
+
27
+ ### Configuration
28
+
29
+ #### Redis connection
30
+
31
+ To configure Redis connection, set `Conflow.redis` attribute to a `Redis` or `ConnectionPool` instance.
32
+
33
+ ```ruby
34
+ Conflow.redis = Redis.new(host: "127.0.0.1", port: 6379)
35
+ # or
36
+ require "connection_pool"
37
+ Conflow.redis = ConnectionPool.new(size: 5, timeout: 5) { Redis.new(host: "127.0.0.1", port: 6379) }
38
+ ```
39
+
40
+ #### Redis script caching
41
+
42
+ By default, gem caches it's scripts in Redis server. To disable this behaviour, set `cache_scripts` to false:
43
+
44
+ ```ruby
45
+ Conflow::Redis::Scripts.cache_scripts = false
46
+ ```
47
+
48
+ ### Defining flows
49
+
50
+ In order to define a flow, first you need to supply a way to enqueue jobs.
51
+
52
+ `Conflow` does not make any assumptions about this process - you can enqueue Sidekiq job, send a RabbitMQ event or send an email to a Very Important Person with flow ID and job ID.
53
+
54
+ ```ruby
55
+ class ApplicationFlow < Conflow::Flow
56
+ def queue(job)
57
+ Sidekiq::Client.enqueue(FlowWorkerJob, id, job.id)
58
+ end
59
+ end
60
+ ```
61
+
62
+ `id` (`Conflow::Flow#id`) and `job.id` (`Conflow::Job#id`) is enough to identify job and execute it properly. Make sure that you send both of these values and it will be OK.
63
+
64
+ You can define actual jobs to be performed using `#configure` method:
65
+
66
+ ```ruby
67
+ class MyFlow < ApplicationFlow
68
+ def configure(id:, strict:)
69
+ run UpsertJob, params: { id: id }
70
+ run CheckerJob, params: { id: id }, after: UpsertJob if strict
71
+ end
72
+ end
73
+ ```
74
+
75
+ To create flow, use `.create` method:
76
+
77
+ ```ruby
78
+ MyFlow.create(id: 320, strict: false)
79
+ MyFlow.create(id: 15, strict: true)
80
+ ```
81
+
82
+ #### Dependencies
83
+
84
+ You can use `after` option to define dependencies. `after` accepts a `Class`, `Conflow::Job` instance or `Integer` with id of the job - or an array with any combination of these.
85
+
86
+ ```ruby
87
+ class MyFlow < ApplicationFlow
88
+ def configure
89
+ first = run FirstJob
90
+ independent = run IndependentJob
91
+
92
+ run SecondJob, after: [FirstJob, independent]
93
+ run FinishUp, after: SecondJob
94
+ end
95
+ end
96
+ ```
97
+
98
+ ![Created graph](https://camo.githubusercontent.com/0b1ee59994323900906264ea50fbc9169e4d21dd/68747470733a2f2f63686172742e676f6f676c65617069732e636f6d2f63686172743f63686c3d646967726170682b472b2537422530442530412b2b72616e6b6469722533444c522533422530442530412b2b25323253544152542532322b2d2533452b25323246697273744a6f622532322530442530412b2b25323253544152542532322b2d2533452b253232496e646570656e64656e744a6f622532322530442530412b2b25323246697273744a6f622532322b2d2533452b2532325365636f6e644a6f622532322530442530412b2b253232496e646570656e64656e744a6f622532322b2d2533452b2532325365636f6e644a6f622532322530442530412b2b2532325365636f6e644a6f622532322b2d2533452b25323246696e69736855702532322530442530412b2b25323246696e69736855702532322b2d2533452b253232454e442532322530442530412537442530442530412b266368743d6776)
99
+
100
+ ### Performing jobs
101
+
102
+ To perform job, use `Conflow::Worker` mixin. It adds `#perform` method, which accepts two arguments: IDs of the flow and the job.
103
+
104
+ Simple `Conflow::Worker` that is also `Sidekiq::Worker`:
105
+
106
+ ```ruby
107
+ class FlowWorkerJob
108
+ include Conflow::Worker
109
+ include Sidekiq::Worker # order is important!
110
+
111
+ def perform(flow_id, job_id)
112
+ super do |worker_class, params|
113
+ worker_class.new(params).call
114
+ end
115
+ end
116
+ end
117
+ ```
118
+
119
+ For previously defined flow, executing this flow would result in:
120
+
121
+ ```ruby
122
+ FirstJob.new({}).call
123
+ IndependentJob.new({}).call # order of the first two is not defined
124
+
125
+ SecondJob.new({}).call
126
+
127
+ FinishUp.new({}).call
128
+ ```
129
+
130
+ ## Development
131
+
132
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
133
+
134
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
135
+
136
+ ## Contributing
137
+
138
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/conflow. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
139
+
140
+ ## License
141
+
142
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
143
+
144
+ ## Code of Conduct
145
+
146
+ Everyone interacting in the Conflow project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/conflow/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "conflow"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "pry"
11
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/conflow.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "conflow/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "conflow"
9
+ spec.version = Conflow::VERSION
10
+ spec.authors = ["Michał Begejowicz"]
11
+ spec.email = ["michal.begejowicz@codesthq.com"]
12
+
13
+ spec.required_ruby_version = "~> 2.3"
14
+
15
+ spec.summary = "Redis-backed handling of complicated flows"
16
+ spec.description = "Redis-backed handling of complicated flows"
17
+ spec.homepage = "https://github.com/fanfilmu/conflow"
18
+ spec.license = "MIT"
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "redis", "~> 4.0"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "connection_pool", "~> 2.2"
27
+ spec.add_development_dependency "pry", "~> 0.11"
28
+ spec.add_development_dependency "rake", "~> 12.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency "rubocop", "~> 0.51"
31
+ spec.add_development_dependency "simplecov", "~> 0.15"
32
+ end