job_notifier 1.2.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +104 -0
- data/.circleci/setup-rubygems.sh +3 -0
- data/.rubocop.yml +76 -605
- data/.ruby-version +1 -1
- data/CHANGELOG.md +31 -2
- data/Gemfile.lock +191 -127
- data/README.md +18 -6
- data/app/assets/javascripts/job_notifier/notifier.js +4 -0
- data/app/models/job_notifier/job.rb +3 -2
- data/job_notifier.gemspec +9 -5
- data/lib/generators/job_notifier/install/templates/initializer.rb +4 -0
- data/lib/job_notifier.rb +6 -1
- data/lib/job_notifier/engine.rb +10 -4
- data/lib/job_notifier/error.rb +5 -5
- data/lib/job_notifier/logger.rb +1 -0
- data/lib/job_notifier/notifier.rb +6 -6
- data/lib/job_notifier/version.rb +1 -1
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/app/assets/stylesheets/application.css +3 -3
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/dummy/app/javascript/packs/application.js +15 -0
- data/spec/dummy/app/jobs/application_job.rb +7 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +10 -9
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/rails +3 -3
- data/spec/dummy/bin/rake +2 -2
- data/spec/dummy/bin/setup +18 -14
- data/spec/dummy/config.ru +3 -1
- data/spec/dummy/config/application.rb +12 -21
- data/spec/dummy/config/boot.rb +3 -3
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +2 -2
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/development.rb +49 -14
- data/spec/dummy/config/environments/production.rb +63 -22
- data/spec/dummy/config/environments/test.rb +29 -12
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/assets.rb +4 -3
- data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -3
- data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -1
- data/spec/dummy/config/initializers/job_notifier.rb +4 -0
- data/spec/dummy/config/initializers/permissions_policy.rb +11 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -2
- data/spec/dummy/config/locales/en.yml +11 -1
- data/spec/dummy/config/puma.rb +43 -0
- data/spec/dummy/config/routes.rb +0 -1
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/public/404.html +6 -6
- data/spec/dummy/public/422.html +6 -6
- data/spec/dummy/public/500.html +6 -6
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/factories/job_notifier_jobs.rb +4 -4
- data/spec/lib/job_notifier/notifier_spec.rb +24 -7
- data/spec/rails_helper.rb +2 -2
- data/spec/spec_helper.rb +2 -0
- metadata +98 -26
- data/.travis.yml +0 -14
@@ -1,5 +1,5 @@
|
|
1
1
|
module JobNotifier
|
2
|
-
class Job <
|
2
|
+
class Job < ApplicationRecord
|
3
3
|
extend Enumerize
|
4
4
|
|
5
5
|
STATUSES = [:pending, :finished, :failed]
|
@@ -9,7 +9,8 @@ module JobNotifier
|
|
9
9
|
def self.update_feedback(job_id, data, status)
|
10
10
|
job = JobNotifier::Job.find_by(job_id: job_id)
|
11
11
|
return unless job
|
12
|
-
|
12
|
+
|
13
|
+
job.update(result: data.to_s, status: status, notified: false)
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.unnotified_by_identifier(encoded_identifier)
|
data/job_notifier.gemspec
CHANGED
@@ -17,14 +17,18 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.files = `git ls-files`.split($/).reject { |fn| fn.start_with? "spec" }
|
18
18
|
s.test_files = Dir["spec/**/*"]
|
19
19
|
|
20
|
-
s.add_dependency "rails", ">=
|
21
|
-
|
20
|
+
s.add_dependency "rails", ">= 6.0"
|
21
|
+
|
22
22
|
s.add_dependency "colorize", ">= 0.7.7"
|
23
|
+
s.add_dependency "enumerize", ">= 1.0"
|
23
24
|
s.add_dependency "silencer", "1.0.0.rc3"
|
24
25
|
|
26
|
+
s.add_development_dependency "coveralls"
|
27
|
+
s.add_development_dependency "factory_bot_rails"
|
25
28
|
s.add_development_dependency "pry"
|
29
|
+
s.add_development_dependency "rspec_junit_formatter"
|
30
|
+
s.add_development_dependency "rspec-rails"
|
31
|
+
s.add_development_dependency "rubocop", "~> 1.9"
|
32
|
+
s.add_development_dependency "rubocop-rails"
|
26
33
|
s.add_development_dependency "sqlite3"
|
27
|
-
s.add_development_dependency "rspec-rails", "~> 3.4.0"
|
28
|
-
s.add_development_dependency "factory_girl_rails", "~> 4.6.0"
|
29
|
-
s.add_development_dependency "coveralls"
|
30
34
|
end
|
@@ -2,4 +2,8 @@ JobNotifier.setup do |config|
|
|
2
2
|
# If you're using an app client that is not part of rails project where Job Notifier gem was
|
3
3
|
# installed, you can define a custom root_url. For example: "http://app.platan.us/"
|
4
4
|
# config.root_url = "/"
|
5
|
+
|
6
|
+
# This gem uses the polling technique to inform what's happening with your jobs. This generates
|
7
|
+
# a noisy log output. If you want to silence this output
|
8
|
+
# config.silenced_log = false
|
5
9
|
end
|
data/lib/job_notifier.rb
CHANGED
@@ -6,13 +6,18 @@ require "silencer"
|
|
6
6
|
module JobNotifier
|
7
7
|
extend self
|
8
8
|
|
9
|
-
attr_writer :root_url
|
9
|
+
attr_writer :root_url, :silenced_log
|
10
10
|
|
11
11
|
def root_url
|
12
12
|
return "/" unless @root_url
|
13
13
|
@root_url
|
14
14
|
end
|
15
15
|
|
16
|
+
def silenced_log
|
17
|
+
return false unless @silenced_log
|
18
|
+
@silenced_log
|
19
|
+
end
|
20
|
+
|
16
21
|
def setup
|
17
22
|
yield self
|
18
23
|
require "job_notifier"
|
data/lib/job_notifier/engine.rb
CHANGED
@@ -4,7 +4,7 @@ module JobNotifier
|
|
4
4
|
|
5
5
|
config.generators do |g|
|
6
6
|
g.test_framework :rspec, fixture: false
|
7
|
-
g.fixture_replacement :
|
7
|
+
g.fixture_replacement :factory_bot, dir: "spec/factories"
|
8
8
|
end
|
9
9
|
|
10
10
|
config.serve_static_files = true
|
@@ -20,9 +20,15 @@ module JobNotifier
|
|
20
20
|
helper(JobNotifier::ApplicationHelper)
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
Rails
|
25
|
-
|
23
|
+
if JobNotifier.silenced_log
|
24
|
+
Rails.application.middleware.swap(
|
25
|
+
Rails::Rack::Logger,
|
26
|
+
Silencer::Logger,
|
27
|
+
silence: [%r{\/job_notifier\/\w+\/jobs\/\w+.json}]
|
28
|
+
)
|
29
|
+
|
30
|
+
Rails.application.middleware.insert_before(Silencer::Logger, JobNotifier::Logger)
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
data/lib/job_notifier/error.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
module JobNotifier
|
2
2
|
module Error
|
3
|
-
class InvalidIdentifier <
|
3
|
+
class InvalidIdentifier < RuntimeError
|
4
4
|
def initialize
|
5
5
|
super("you need to pass a non blank identifier")
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
class MissingAttributes <
|
9
|
+
class MissingAttributes < RuntimeError
|
10
10
|
def initialize
|
11
11
|
super("you need to execute identify_job_through method on host model")
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
class BlankAttribute <
|
15
|
+
class BlankAttribute < RuntimeError
|
16
16
|
def initialize(attribute)
|
17
17
|
super("#{attribute} cant be blank")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
class InvalidAdapter <
|
21
|
+
class InvalidAdapter < RuntimeError
|
22
22
|
def initialize
|
23
23
|
file_names = JobNotifier::Adapters.names.join(", ")
|
24
24
|
super("The adapter must be one of: #{file_names}")
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
class Validation <
|
28
|
+
class Validation < RuntimeError
|
29
29
|
attr_reader :error
|
30
30
|
|
31
31
|
def initialize(error)
|
data/lib/job_notifier/logger.rb
CHANGED
@@ -6,11 +6,11 @@ module JobNotifier
|
|
6
6
|
def perform(*args)
|
7
7
|
result = perform_with_feedback(*args)
|
8
8
|
save_success_feedback(result)
|
9
|
-
rescue JobNotifier::Error::Validation =>
|
10
|
-
save_error_feedback(
|
11
|
-
rescue StandardError =>
|
9
|
+
rescue JobNotifier::Error::Validation => e
|
10
|
+
save_error_feedback(e.error)
|
11
|
+
rescue StandardError => e
|
12
12
|
save_error_feedback("unknown")
|
13
|
-
raise
|
13
|
+
raise e
|
14
14
|
end
|
15
15
|
|
16
16
|
def save_error_feedback(error)
|
@@ -27,7 +27,7 @@ module JobNotifier
|
|
27
27
|
raise JobNotifier::Error::InvalidIdentifier.new if identifier.blank?
|
28
28
|
|
29
29
|
JobNotifier::Job.create!(
|
30
|
-
identifier: identifier,
|
30
|
+
identifier: (identifier.to_sym == :without_owner ? nil : identifier),
|
31
31
|
job_id: job.job_id,
|
32
32
|
job_class: self.class.name
|
33
33
|
)
|
@@ -37,4 +37,4 @@ module JobNotifier
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
ActiveJob::Base.
|
40
|
+
ActiveJob::Base.include(JobNotifier::Notifier)
|
data/lib/job_notifier/version.rb
CHANGED
data/spec/dummy/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
2
|
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
3
|
|
4
|
-
|
4
|
+
require_relative "config/application"
|
5
5
|
|
6
6
|
Rails.application.load_tasks
|
@@ -6,9 +6,9 @@
|
|
6
6
|
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
7
|
*
|
8
8
|
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any
|
10
|
-
*
|
11
|
-
* file per style scope.
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
12
|
*
|
13
13
|
*= require_tree .
|
14
14
|
*= require_self
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require rails-ujs
|
14
|
+
//= require activestorage
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class ApplicationJob < ActiveJob::Base
|
2
|
+
# Automatically retry jobs that encountered a deadlock
|
3
|
+
# retry_on ActiveRecord::Deadlocked
|
4
|
+
|
5
|
+
# Most jobs are safe to ignore if the underlying records are no longer available
|
6
|
+
# discard_on ActiveJob::DeserializationError
|
7
|
+
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
|
-
<head>
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
</head>
|
9
|
-
<body <%= job_identifier_for(@current_user) %>>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<%= csrf_meta_tags %>
|
7
|
+
<%= csp_meta_tag %>
|
10
8
|
|
11
|
-
<%=
|
9
|
+
<%= stylesheet_link_tag 'application', media: 'all' %>
|
10
|
+
</head>
|
12
11
|
|
13
|
-
|
12
|
+
<body>
|
13
|
+
<%= yield %>
|
14
|
+
</body>
|
14
15
|
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %>
|
data/spec/dummy/bin/rails
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
APP_PATH = File.expand_path('
|
3
|
-
require_relative
|
4
|
-
require
|
2
|
+
APP_PATH = File.expand_path('../config/application', __dir__)
|
3
|
+
require_relative "../config/boot"
|
4
|
+
require "rails/commands"
|
data/spec/dummy/bin/rake
CHANGED
data/spec/dummy/bin/setup
CHANGED
@@ -1,29 +1,33 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require
|
2
|
+
require "fileutils"
|
3
3
|
|
4
4
|
# path to your application root.
|
5
|
-
APP_ROOT =
|
5
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def system!(*args)
|
8
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
9
|
+
end
|
10
|
+
|
11
|
+
FileUtils.chdir APP_ROOT do
|
12
|
+
# This script is a way to set up or update your development environment automatically.
|
13
|
+
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
|
14
|
+
# Add necessary setup steps to this file.
|
10
15
|
|
11
|
-
puts
|
12
|
-
system
|
13
|
-
system
|
16
|
+
puts '== Installing dependencies =='
|
17
|
+
system! 'gem install bundler --conservative'
|
18
|
+
system('bundle check') || system!('bundle install')
|
14
19
|
|
15
20
|
# puts "\n== Copying sample files =="
|
16
|
-
# unless File.exist?(
|
17
|
-
#
|
21
|
+
# unless File.exist?('config/database.yml')
|
22
|
+
# FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
|
18
23
|
# end
|
19
24
|
|
20
25
|
puts "\n== Preparing database =="
|
21
|
-
system
|
26
|
+
system! 'bin/rails db:prepare'
|
22
27
|
|
23
28
|
puts "\n== Removing old logs and tempfiles =="
|
24
|
-
system
|
25
|
-
system "rm -rf tmp/cache"
|
29
|
+
system! 'bin/rails log:clear tmp:clear'
|
26
30
|
|
27
31
|
puts "\n== Restarting application server =="
|
28
|
-
system
|
32
|
+
system! 'bin/rails restart'
|
29
33
|
end
|
data/spec/dummy/config.ru
CHANGED
@@ -1,31 +1,22 @@
|
|
1
|
-
|
1
|
+
require_relative "boot"
|
2
2
|
|
3
|
-
|
4
|
-
require "active_record/railtie"
|
5
|
-
require "action_controller/railtie"
|
6
|
-
require "action_mailer/railtie"
|
7
|
-
require "action_view/railtie"
|
8
|
-
require "sprockets/railtie"
|
9
|
-
# require "rails/test_unit/railtie"
|
3
|
+
require "rails/all"
|
10
4
|
|
5
|
+
# Require the gems listed in Gemfile, including any gems
|
6
|
+
# you've limited to :test, :development, or :production.
|
11
7
|
Bundler.require(*Rails.groups)
|
12
8
|
require "job_notifier"
|
13
9
|
|
14
10
|
module Dummy
|
15
11
|
class Application < Rails::Application
|
16
|
-
|
17
|
-
# Application configuration should go into files in config/initializers
|
18
|
-
# -- all .rb files in that directory are automatically loaded.
|
12
|
+
config.load_defaults Rails::VERSION::STRING.to_f
|
19
13
|
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
|
24
|
-
#
|
25
|
-
# config.
|
26
|
-
# config.
|
27
|
-
|
28
|
-
# Do not swallow errors in after_commit/after_rollback callbacks.
|
29
|
-
config.active_record.raise_in_transactional_callbacks = true
|
14
|
+
# Configuration for the application, engines, and railties goes here.
|
15
|
+
#
|
16
|
+
# These settings can be overridden in specific environments using the files
|
17
|
+
# in config/environments, which are processed later.
|
18
|
+
#
|
19
|
+
# config.time_zone = "Central Time (US & Canada)"
|
20
|
+
# config.eager_load_paths << Rails.root.join("extras")
|
30
21
|
end
|
31
22
|
end
|