Skip to content

Commit

Permalink
feat(): add config option to disable silencer gem
Browse files Browse the repository at this point in the history
  • Loading branch information
ldlsegovia committed Jun 16, 2017
1 parent bcaba1a commit 4fa9985
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 15 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

### Unreleased

##### Added

- Add silenced_log config option to disable silencer gem.

### v1.2.4

##### Fixed
Expand All @@ -12,7 +18,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

##### Changed

- Avoid raising error with undefined verify_authenticity_token method
- Avoid raising error with undefined verify_authenticity_token method.

### v1.2.2

Expand Down Expand Up @@ -73,4 +79,4 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### v0.1.0

* Initial release.
- Initial release.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

It's a Rails engine built on top of [Active Job](https://github.com/rails/activejob) in order to **improve user experience related to background processes**. To achieve this goal, the gem allows us to:

1. **Relate jobs with entities**
- **Relate jobs with entities**

Using [Active Job](https://github.com/rails/activejob), you can perform background jobs but, you can not relate them with, for example, a logged user. Job Notifier allows you to connect an entity with a job easily.

1. **Persist job results**
- **Persist job results**

Using [Active Job](https://github.com/rails/activejob), you can run jobs in background but, you are not be able to store the result of those jobs. This is a desired behavior if you, for example, want to provide validation feedback to users.

1. **Notify users when their jobs change state.**
- **Notify users when their jobs change state.**

Using [Active Job](https://github.com/rails/activejob), you can run jobs in background but, you lose a real time response. To bring a solution to this issue, Job Notifier, through polling technique, gives you a way to know what's happening with your jobs.
Using [Active Job](https://github.com/rails/activejob), you can run jobs in background but, you lose a real time response. To bring a solution to this issue, Job Notifier, through polling technique, gives you a way to know what's happening with your jobs.

## Installation

Expand Down
4 changes: 4 additions & 0 deletions lib/generators/job_notifier/install/templates/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
# If you're using an app client that is not part of rails project where Job Notifier gem was
# installed, you can define a custom root_url. For example: "http://app.platan.us/"
# config.root_url = "/"

# This gem uses the polling technique to inform what's happening with your jobs. This generates
# a noisy log output. If you want to silence this output
# config.silenced_log = false
end
7 changes: 6 additions & 1 deletion lib/job_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
module JobNotifier
extend self

attr_writer :root_url
attr_writer :root_url, :silenced_log

def root_url
return "/" unless @root_url
@root_url
end

def silenced_log
return false unless @silenced_log
@silenced_log
end

def setup
yield self
require "job_notifier"
Expand Down
12 changes: 9 additions & 3 deletions lib/job_notifier/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ class Engine < ::Rails::Engine
helper(JobNotifier::ApplicationHelper)
end

Rails.application.middleware.swap(
Rails::Rack::Logger, Silencer::Logger, silence: [%r{\/job_notifier\/\w+\/jobs\/\w+.json}])
Rails.application.middleware.insert_before(Silencer::Logger, JobNotifier::Logger)
if JobNotifier.silenced_log
Rails.application.middleware.swap(
Rails::Rack::Logger,
Silencer::Logger,
silence: [%r{\/job_notifier\/\w+\/jobs\/\w+.json}]
)

Rails.application.middleware.insert_before(Silencer::Logger, JobNotifier::Logger)
end
end
end
end
10 changes: 5 additions & 5 deletions lib/job_notifier/error.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
module JobNotifier
module Error
class InvalidIdentifier < Exception
class InvalidIdentifier < RuntimeError
def initialize
super("you need to pass a non blank identifier")
end
end

class MissingAttributes < Exception
class MissingAttributes < RuntimeError
def initialize
super("you need to execute identify_job_through method on host model")
end
end

class BlankAttribute < Exception
class BlankAttribute < RuntimeError
def initialize(attribute)
super("#{attribute} cant be blank")
end
end

class InvalidAdapter < Exception
class InvalidAdapter < RuntimeError
def initialize
file_names = JobNotifier::Adapters.names.join(", ")
super("The adapter must be one of: #{file_names}")
end
end

class Validation < Exception
class Validation < RuntimeError
attr_reader :error

def initialize(error)
Expand Down
4 changes: 4 additions & 0 deletions spec/dummy/config/initializers/job_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
# If you're using an app client that is not part of rails project where Job Notifier gem was
# installed, you can define a custom root_url. For example: "http://app.platan.us/"
# config.root_url = "/"

# This gem uses the polling technique to inform what's happening with your jobs. This generates
# a noisy log output. If you want to silence this output
# config.silenced_log = false
end

0 comments on commit 4fa9985

Please sign in to comment.