Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite to use graphs natively thanks to RedisGraph module #96

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ jobs:
test:
services:
redis:
image: redis:alpine
image: redis/redis-stack-server
ports: ["6379:6379"]
options: --entrypoint redis-server

runs-on: ubuntu-latest
strategy:
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ gemspec
rails_version = ENV['RAILS_VERSION'] || '< 7.0'
rails_version = "~> #{rails_version}" if rails_version =~ /^\d/
gem 'activejob', rails_version
gem "benchmark-ips", '~> 2.10.0'

platforms :mri, :ruby do
gem 'yajl-ruby'
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,12 @@ Running `NotifyWorkflow.create` inserts multiple keys into Redis every time it i
Gush.configure do |config|
config.redis_url = "redis://localhost:6379"
config.concurrency = 5
config.ttl = 3600*24*7
end
```

And you need to call `flow.expire!` (optionally passing custom TTL value overriding `config.ttl`). This gives you control whether to expire data for specific workflow. Best NOT to set TTL to be too short (like minutes) but about a week in length. And you can run `Client.expire_workflow` and `Client.expire_job` passing appropriate IDs and TTL (pass -1 to NOT expire) values.

### Avoid overlapping workflows

Since we do not know how long our workflow execution will take we might want to avoid starting the next scheduled workflow iteration while the current one with same class is still running. Long term this could be moved into core library, perhaps `Workflow.find_by_class(klass)`
Since we do not know how long our workflow execution will take we might want to avoid starting the next scheduled workflow iteration while the current one with same class is still running. Long term this could be moved into core library, perhaps `Workflow.find_by_class(klass)`

```ruby
# config/initializers/gush.rb
Expand Down
58 changes: 58 additions & 0 deletions benchmark.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require "pathname"
require "bundler"
require "pry"
Bundler.require

bin_file = Pathname.new(__FILE__).realpath
# add self to libpath
$:.unshift File.expand_path("../../lib", bin_file)

require 'benchmark/ips'
require 'gush'

class Prepare < Gush::Job; end
class FetchFirstJob < Gush::Job; end
class FetchSecondJob < Gush::Job; end
class PersistFirstJob < Gush::Job; end
class PersistSecondJob < Gush::Job; end
class NormalizeJob < Gush::Job; end

class TestWorkflow < Gush::Workflow
def configure
run Prepare

run NormalizeJob, after: PersistSecondJob

run FetchFirstJob, after: Prepare
run FetchSecondJob, after: Prepare

run PersistFirstJob, after: FetchFirstJob, before: NormalizeJob
run PersistSecondJob, after: FetchSecondJob
end
end

flow = TestWorkflow.create
client = Gush::Client.new

Benchmark.ips do |x|
# Configure the number of seconds used during
# the warmup phase (default 2) and calculation phase (default 5)
x.config(:time => 5, :warmup => 2)

# These parameters can also be configured this way
x.time = 5
x.warmup = 2


x.report("init") do
TestWorkflow.new
end

x.report("creation") do
TestWorkflow.create
end

# x.report "initial jobs" do

# end
end
67 changes: 67 additions & 0 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env ruby
require "pathname"
require "bundler"
require "pry"
Bundler.require

bin_file = Pathname.new(__FILE__).realpath
# add self to libpath
$:.unshift File.expand_path("../../lib", bin_file)

require 'gush'


class Prepare < Gush::Job; end
class FetchFirstJob < Gush::Job; end
class FetchSecondJob < Gush::Job; end
class PersistFirstJob < Gush::Job; end
class PersistSecondJob < Gush::Job; end
class NormalizeJob < Gush::Job; end

class TestWorkflow < Gush::Workflow
def configure
run Prepare

run NormalizeJob, after: PersistSecondJob

run FetchFirstJob, after: Prepare
run FetchSecondJob, after: Prepare

run PersistFirstJob, after: FetchFirstJob, before: NormalizeJob
run PersistSecondJob, after: FetchSecondJob
end
end

class UpcaseJob < Gush::Job
def perform
output params[:input].upcase
end
end

class PrefixJob < Gush::Job
def perform
output params[:prefix].capitalize
end
end

class PrependJob < Gush::Job
def perform
string = "#{payloads.find { |j| j[:class] == 'PrefixJob'}[:output]}: #{payloads.find { |j| j[:class] == 'UpcaseJob'}[:output]}"
output string
end
end

class PayloadWorkflow < Gush::Workflow
def configure
run UpcaseJob, params: {input: "some text"}
run PrefixJob, params: {prefix: "a prefix"}
run PrependJob, after: [UpcaseJob, PrefixJob]
end
end

# flow = TestWorkflow.create

flow2 = PayloadWorkflow.create


binding.pry
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
redis:
image: "redis/redis-stack"
ports:
- "6379:6379"
- "8001:8001"
15 changes: 7 additions & 8 deletions gush.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@ Gem::Specification.new do |spec|
spec.homepage = "https://github.com/chaps-io/gush"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0")
spec.files = Dir['lib/**/*.rb'] + [['bin/gush']]
spec.executables = "gush"
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_dependency "activejob", ">= 4.2.7", "< 7.1"
spec.add_dependency "concurrent-ruby", "~> 1.0"
spec.add_dependency "multi_json", "~> 1.11"
spec.add_dependency "redis", ">= 3.2", "< 5"
spec.add_dependency "redis-mutex", "~> 4.0.1"
spec.add_dependency "hiredis", "~> 0.6"
spec.add_dependency "graphviz", "~> 1.2"
spec.add_dependency "oj", "~> 3.13.21"
spec.add_dependency "redis", "~> 5.0.5"
spec.add_dependency "redlock", "~> 1.3.0"
spec.add_dependency "graphviz", "~> 1.2.1"
spec.add_dependency "terminal-table", ">= 1.4", "< 3.1"
spec.add_dependency "paint", "~> 2.2"
spec.add_dependency "paint", "~> 2.3.0"
spec.add_dependency "thor", ">= 0.19", "< 1.3"
spec.add_dependency "launchy", "~> 2.4"
spec.add_dependency "connection_pool", "~> 2.3.0"
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake", "~> 10.4"
spec.add_development_dependency "rspec", '~> 3.0'
Expand Down
2 changes: 0 additions & 2 deletions lib/gush.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
require "bundler/setup"

require "graphviz"
require "hiredis"
require "pathname"
require "redis"
require "securerandom"
require "multi_json"

require "gush/json"
require "gush/cli"
Expand Down