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.
Files changed (67) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +104 -0
  3. data/.circleci/setup-rubygems.sh +3 -0
  4. data/.rubocop.yml +76 -605
  5. data/.ruby-version +1 -1
  6. data/CHANGELOG.md +31 -2
  7. data/Gemfile.lock +191 -127
  8. data/README.md +18 -6
  9. data/app/assets/javascripts/job_notifier/notifier.js +4 -0
  10. data/app/models/job_notifier/job.rb +3 -2
  11. data/job_notifier.gemspec +9 -5
  12. data/lib/generators/job_notifier/install/templates/initializer.rb +4 -0
  13. data/lib/job_notifier.rb +6 -1
  14. data/lib/job_notifier/engine.rb +10 -4
  15. data/lib/job_notifier/error.rb +5 -5
  16. data/lib/job_notifier/logger.rb +1 -0
  17. data/lib/job_notifier/notifier.rb +6 -6
  18. data/lib/job_notifier/version.rb +1 -1
  19. data/spec/dummy/Rakefile +1 -1
  20. data/spec/dummy/app/assets/config/manifest.js +3 -0
  21. data/spec/dummy/app/assets/stylesheets/application.css +3 -3
  22. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  23. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  24. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  25. data/spec/dummy/app/javascript/packs/application.js +15 -0
  26. data/spec/dummy/app/jobs/application_job.rb +7 -0
  27. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  28. data/spec/dummy/app/models/application_record.rb +3 -0
  29. data/spec/dummy/app/views/layouts/application.html.erb +10 -9
  30. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  31. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  32. data/spec/dummy/bin/rails +3 -3
  33. data/spec/dummy/bin/rake +2 -2
  34. data/spec/dummy/bin/setup +18 -14
  35. data/spec/dummy/config.ru +3 -1
  36. data/spec/dummy/config/application.rb +12 -21
  37. data/spec/dummy/config/boot.rb +3 -3
  38. data/spec/dummy/config/cable.yml +10 -0
  39. data/spec/dummy/config/database.yml +2 -2
  40. data/spec/dummy/config/environment.rb +1 -1
  41. data/spec/dummy/config/environments/development.rb +49 -14
  42. data/spec/dummy/config/environments/production.rb +63 -22
  43. data/spec/dummy/config/environments/test.rb +29 -12
  44. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  45. data/spec/dummy/config/initializers/assets.rb +4 -3
  46. data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -3
  47. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  48. data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
  49. data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -1
  50. data/spec/dummy/config/initializers/job_notifier.rb +4 -0
  51. data/spec/dummy/config/initializers/permissions_policy.rb +11 -0
  52. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -2
  53. data/spec/dummy/config/locales/en.yml +11 -1
  54. data/spec/dummy/config/puma.rb +43 -0
  55. data/spec/dummy/config/routes.rb +0 -1
  56. data/spec/dummy/config/storage.yml +34 -0
  57. data/spec/dummy/public/404.html +6 -6
  58. data/spec/dummy/public/422.html +6 -6
  59. data/spec/dummy/public/500.html +6 -6
  60. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  61. data/spec/dummy/public/apple-touch-icon.png +0 -0
  62. data/spec/factories/job_notifier_jobs.rb +4 -4
  63. data/spec/lib/job_notifier/notifier_spec.rb +24 -7
  64. data/spec/rails_helper.rb +2 -2
  65. data/spec/spec_helper.rb +2 -0
  66. metadata +98 -26
  67. data/.travis.yml +0 -14
@@ -40,6 +40,10 @@
40
40
  JobNotifier.onPendingJobsLoad = function() {
41
41
  var data = JSON.parse(this.responseText);
42
42
 
43
+ if (data.jobs) {
44
+ data = data.jobs;
45
+ }
46
+
43
47
  if(data.length === 0) {
44
48
  JobNotifier.findJobs();
45
49
  return;
@@ -1,5 +1,5 @@
1
1
  module JobNotifier
2
- class Job < ActiveRecord::Base
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
- job.update_columns(result: data.to_s, status: status, notified: false)
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", ">= 4.2.0"
21
- s.add_dependency "enumerize", ">= 1.0"
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"
@@ -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 :factory_girl, dir: "spec/factories"
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
- Rails.application.middleware.swap(
24
- Rails::Rack::Logger, Silencer::Logger, silence: [%r{\/job_notifier\/\w+\/jobs\/\w+.json}])
25
- Rails.application.middleware.insert_before(Silencer::Logger, JobNotifier::Logger)
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
@@ -1,31 +1,31 @@
1
1
  module JobNotifier
2
2
  module Error
3
- class InvalidIdentifier < Exception
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 < Exception
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 < Exception
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 < Exception
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 < Exception
28
+ class Validation < RuntimeError
29
29
  attr_reader :error
30
30
 
31
31
  def initialize(error)
@@ -18,6 +18,7 @@ module JobNotifier
18
18
  response.each do |resp|
19
19
  next if resp.blank?
20
20
  result = JSON.parse(resp)
21
+ result = result["jobs"] if result.is_a?(Hash)
21
22
  next if result.blank?
22
23
  puts build_log_msg(result)
23
24
  end
@@ -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 => ex
10
- save_error_feedback(ex.error)
11
- rescue StandardError => ex
9
+ rescue JobNotifier::Error::Validation => e
10
+ save_error_feedback(e.error)
11
+ rescue StandardError => e
12
12
  save_error_feedback("unknown")
13
- raise ex
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.send(:include, JobNotifier::Notifier)
40
+ ActiveJob::Base.include(JobNotifier::Notifier)
@@ -1,3 +1,3 @@
1
1
  module JobNotifier
2
- VERSION = "1.2.3"
2
+ VERSION = "2.0.0"
3
3
  end
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
- require File.expand_path('../config/application', __FILE__)
4
+ require_relative "config/application"
5
5
 
6
6
  Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../stylesheets .css
3
+ //= link job_notifier_manifest.js
@@ -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 styles
10
- * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
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,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ end
4
+ end
@@ -1,5 +1,2 @@
1
1
  class ApplicationController < ActionController::Base
2
- # Prevent CSRF attacks by raising an exception.
3
- # For APIs, you may want to use :null_session instead.
4
- protect_from_forgery with: :exception
5
2
  end
@@ -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
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -1,14 +1,15 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
- <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
- <%= csrf_meta_tags %>
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
- <%= yield %>
9
+ <%= stylesheet_link_tag 'application', media: 'all' %>
10
+ </head>
12
11
 
13
- </body>
12
+ <body>
13
+ <%= yield %>
14
+ </body>
14
15
  </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </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('../../config/application', __FILE__)
3
- require_relative '../config/boot'
4
- require 'rails/commands'
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative "../config/boot"
4
+ require "rails/commands"
data/spec/dummy/bin/rake CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require_relative '../config/boot'
3
- require 'rake'
2
+ require_relative "../config/boot"
3
+ require "rake"
4
4
  Rake.application.run
data/spec/dummy/bin/setup CHANGED
@@ -1,29 +1,33 @@
1
1
  #!/usr/bin/env ruby
2
- require 'pathname'
2
+ require "fileutils"
3
3
 
4
4
  # path to your application root.
5
- APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
5
+ APP_ROOT = File.expand_path('..', __dir__)
6
6
 
7
- Dir.chdir APP_ROOT do
8
- # This script is a starting point to setup your application.
9
- # Add necessary setup steps to this file:
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 "== Installing dependencies =="
12
- system "gem install bundler --conservative"
13
- system "bundle check || bundle install"
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?("config/database.yml")
17
- # system "cp config/database.yml.sample config/database.yml"
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 "bin/rake db:setup"
26
+ system! 'bin/rails db:prepare'
22
27
 
23
28
  puts "\n== Removing old logs and tempfiles =="
24
- system "rm -f log/*"
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 "touch tmp/restart.txt"
32
+ system! 'bin/rails restart'
29
33
  end
data/spec/dummy/config.ru CHANGED
@@ -1,4 +1,6 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require_relative "config/environment"
4
+
4
5
  run Rails.application
6
+ Rails.application.load_server
@@ -1,31 +1,22 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ require_relative "boot"
2
2
 
3
- # Pick the frameworks you want:
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
- # Settings in config/environments/* take precedence over those specified here.
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
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
21
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
22
- # config.time_zone = 'Central Time (US & Canada)'
23
-
24
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
25
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
26
- # config.i18n.default_locale = :de
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