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

Add executable with Thor #4

Merged
merged 1 commit into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ GoodJob is a multithreaded, Postgres-based ActiveJob backend for Ruby on Rails.
```

1. In production, the scheduler is designed to run in its own process:

```ruby
# TBD
```
```bash
$ bundle exec good_job
```

## Installation
Add this line to your application's Gemfile:
Expand Down
3 changes: 3 additions & 0 deletions bin/good_job
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
require 'good_job/cli'
GoodJob::CLI.start(ARGV)
7 changes: 5 additions & 2 deletions good_job.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ Gem::Specification.new do |spec|
end

spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
spec.executables = "good_job"

spec.add_dependency "rails", "~> 6.0.2", ">= 6.0.2.1"
spec.add_dependency "concurrent-ruby"
spec.add_dependency "rails"
spec.add_dependency "thor"
spec.add_development_dependency "database_cleaner"
spec.add_development_dependency "pg"
spec.add_development_dependency "rspec-rails"
spec.add_development_dependency "database_cleaner"
end
2 changes: 1 addition & 1 deletion lib/good_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "good_job/railtie"
require "rails"

require 'good_job/lockable'
require 'good_job/job'
Expand Down
19 changes: 19 additions & 0 deletions lib/good_job/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'thor'

module GoodJob
class CLI < Thor
RAILS_ENVIRONMENT_RB = File.expand_path("config/environment.rb")

desc :start, "Start jobs"
def start
require RAILS_ENVIRONMENT_RB

scheduler = GoodJob::Scheduler.new
Kernel.loop do
sleep 1
end
end

default_task :start
end
end
22 changes: 22 additions & 0 deletions spec/good_job/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true
require 'rails_helper'
require 'good_job/cli'

RSpec.describe GoodJob::CLI do
before do
stub_const 'GoodJob::CLI::RAILS_ENVIRONMENT_RB', File.expand_path("spec/dummy/config/environment.rb")
end

describe '#start' do
it 'initializes a scheduler' do
scheduler_mock = instance_double GoodJob::Scheduler
allow(GoodJob::Scheduler).to receive(:new).and_return scheduler_mock
allow(Kernel).to receive(:loop)

cli = described_class.new([], {}, {})
cli.start

expect(GoodJob::Scheduler).to have_received(:new)
end
end
end
2 changes: 1 addition & 1 deletion spec/good_job/scheduler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def perform(*args, **kwargs)
self.queue_name = 'test'
self.priority = 50
retry_on(RetryableError, wait: 0, attempts: 3) do |job, error|
puts "FAILED"
# puts "FAILED"
end

def perform(*args, **kwargs)
Expand Down