source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | errbit/errbit | https://github.com/errbit/errbit | app/controllers/api/v1/problems_controller.rb | Ruby | mit | 4,272 | main | 1,518 | # frozen_string_literal: true
module Api
module V1
class ProblemsController < ApplicationController
respond_to :json, :xml
FIELDS = [
"_id", "app_id", "app_name", "environment", "message", "where",
"first_notice_at", "last_notice_at", "resolved", "resolved_at",
"notices_count... |
github | errbit/errbit | https://github.com/errbit/errbit | app/controllers/api/v1/notices_controller.rb | Ruby | mit | 4,272 | main | 862 | # frozen_string_literal: true
module Api
module V1
class NoticesController < ApplicationController
respond_to :json, :xml
def index
query = {}
fields = ["created_at", "message", "error_class"]
if params.key?(:start_date) && params.key?(:end_date)
start_date = Time.... |
github | errbit/errbit | https://github.com/errbit/errbit | app/controllers/api/v3/notices_controller.rb | Ruby | mit | 4,272 | main | 1,655 | # frozen_string_literal: true
module Api
module V3
class NoticesController < ApplicationController
VERSION_TOO_OLD = "Notice for old app version ignored"
UNKNOWN_API_KEY = "Your API key is unknown"
skip_before_action :verify_authenticity_token
skip_before_action :authenticate_user!
... |
github | errbit/errbit | https://github.com/errbit/errbit | app/views/problems/_list.atom.builder | Ruby | mit | 4,272 | main | 517 | # frozen_string_literal: true
feed.updated(problems.first.try(:created_at) || Time.now)
problems.each do |problem|
notice = problem.notices.first
feed.entry(problem, url: app_problem_url(problem.app.to_param, problem.to_param)) do |entry|
entry.title "[#{problem.where}] #{problem.message.to_s.truncate(27)}"
... |
github | errbit/errbit | https://github.com/errbit/errbit | app/mailers/mailer.rb | Ruby | mit | 4,272 | main | 1,791 | # frozen_string_literal: true
# Haml doesn't load routes automatically when called via a rake task.
# This is only necessary when sending test emails (i.e. from rake hoptoad:test)
require Rails.root.join("config/routes.rb")
class Mailer < ApplicationMailer
helper ApplicationHelper
default :from => Errbit::Config... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/err.rb | Ruby | mit | 4,272 | main | 512 | # frozen_string_literal: true
# Represents a set of Notices which can be automatically
# determined to refer to the same Error (Errbit groups
# notices into errs by a notice's fingerprint.)
class Err
include Mongoid::Document
include Mongoid::Timestamps
field :fingerprint
index problem_id: 1
index fingerp... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/problem.rb | Ruby | mit | 4,272 | main | 9,818 | # frozen_string_literal: true
# Represents a single Problem. The problem may have been
# reported as various Errs, but the user has grouped the
# Errs together as belonging to the same problem.
class Problem
include Mongoid::Document
include Mongoid::Timestamps
CACHED_NOTICE_ATTRIBUTES = {
messages: :messa... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/issue_tracker.rb | Ruby | mit | 4,272 | main | 1,054 | # frozen_string_literal: true
class IssueTracker
include Mongoid::Document
include Mongoid::Timestamps
embedded_in :app, inverse_of: :issue_tracker
field :type_tracker, type: String
field :options, type: Hash, default: {}
validate :validate_tracker
def tracker
@tracker ||=
begin
kla... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/issue.rb | Ruby | mit | 4,272 | main | 1,628 | # frozen_string_literal: true
class Issue
include ActiveModel::Model
attr_accessor :problem, :user, :body
def issue_tracker
@issue_tracker ||= problem.app.issue_tracker
end
def tracker
@tracker ||= issue_tracker&.tracker
end
def render_body_args
if tracker.respond_to?(:render_body_args)
... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/notice_fingerprinter.rb | Ruby | mit | 4,272 | main | 1,082 | # frozen_string_literal: true
class NoticeFingerprinter
include Mongoid::Document
include Mongoid::Timestamps
field :error_class, default: true, type: Boolean
field :message, default: true, type: Boolean
field :backtrace_lines, default: -1, type: Integer
field :component, default: true, type: Boolean
fi... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/error_report.rb | Ruby | mit | 4,272 | main | 3,709 | # frozen_string_literal: true
##
# Processes a new error report.
#
# Accepts a hash with the following attributes:
#
# * <tt>:error_class</tt> - the class of error
# * <tt>:message</tt> - the error message
# * <tt>:backtrace</tt> - an array of stack trace lines
#
# * <tt>:request</tt> - a hash of values describing the... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/watcher.rb | Ruby | mit | 4,272 | main | 882 | # frozen_string_literal: true
class Watcher
include Mongoid::Document
include Mongoid::Timestamps
field :email
embedded_in :app, inverse_of: :watchers
belongs_to :user, optional: true
validate :ensure_user_or_email
before_validation :clear_unused_watcher_type
attr_accessor :watcher_type
def wat... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/app.rb | Ruby | mit | 4,272 | main | 6,679 | # frozen_string_literal: true
class App
include Comparable
include Mongoid::Document
include Mongoid::Timestamps
field :name, type: String
field :api_key
field :github_repo
field :bitbucket_repo
field :custom_backtrace_url_template
field :asset_host
field :repository_branch, type: String
field :... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/user.rb | Ruby | mit | 4,272 | main | 3,336 | # frozen_string_literal: true
class User
PER_PAGE = 30
include Mongoid::Document
include Mongoid::Timestamps
devise(*Errbit::Config.devise_modules)
field :email
field :github_login
field :github_oauth_token
field :google_uid
field :name
field :admin, type: Boolean, default: false
field :per_pa... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/comment.rb | Ruby | mit | 4,272 | main | 862 | # frozen_string_literal: true
class Comment
include Mongoid::Document
include Mongoid::Timestamps
after_create :increase_counter_cache
after_create :deliver_email, if: :emailable?
before_destroy :decrease_counter_cache
field :body, type: String
index(user_id: 1)
belongs_to :err, class_name: "Problem... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/notice.rb | Ruby | mit | 4,272 | main | 3,358 | # frozen_string_literal: true
class Notice
include Mongoid::Document
include Mongoid::Timestamps
include ActiveModel::Serializers::Xml
UNAVAILABLE = "N/A"
# Mongo will not accept index keys larger than 1,024 bytes and that includes
# some amount of BSON encoding overhead, so keep it under 1,000 bytes to... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/notification_service.rb | Ruby | mit | 4,272 | main | 1,686 | # frozen_string_literal: true
class NotificationService
LABEL = ""
include Mongoid::Document
include Rails.application.routes.url_helpers
default_url_options[:host] = ActionMailer::Base.default_url_options[:host]
default_url_options[:port] = ActionMailer::Base.default_url_options[:port]
field :room_id,... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/site_config.rb | Ruby | mit | 4,272 | main | 953 | # frozen_string_literal: true
class SiteConfig
CONFIG_SOURCE_SITE = "site"
CONFIG_SOURCE_APP = "app"
include Mongoid::Document
include Mongoid::Timestamps
after_save :denormalize
embeds_one :notice_fingerprinter, autobuild: true
validates_associated :notice_fingerprinter
accepts_nested_attributes_fo... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/backtrace.rb | Ruby | mit | 4,272 | main | 748 | # frozen_string_literal: true
class Backtrace
include Mongoid::Document
include Mongoid::Timestamps
IN_APP_PATH = %r{^(?:\[|/)PROJECT_ROOT\]?(?!(/vendor))/?}
GEMS_PATH = %r{(?:\[|/)GEM_ROOT\]?/gems/([^/]+)}
field :fingerprint
field :lines
index fingerprint: 1
def self.find_or_create(lines)
fing... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/notification_services/slack_service.rb | Ruby | mit | 4,272 | main | 3,029 | # frozen_string_literal: true
module NotificationServices
class SlackService < NotificationService
CHANNEL_NAME_REGEXP = /^#[a-z\d_-]+$/
LABEL = "slack"
FIELDS += [
[:service_url, {
placeholder: "Slack Hook URL (https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX)",
label... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/notification_services/pushover_service.rb | Ruby | mit | 4,272 | main | 952 | # frozen_string_literal: true
module NotificationServices
class PushoverService < NotificationService
LABEL = "pushover"
FIELDS += [
[:api_token, {
placeholder: "User Key",
label: "User Key"
}],
[:subdomain, {
placeholder: "Application API Token",
label: "App... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/notification_services/hoiio_service.rb | Ruby | mit | 4,272 | main | 1,227 | # frozen_string_literal: true
module NotificationServices
class HoiioService < NotificationService
LABEL = "hoiio"
FIELDS += [
[:api_token, {
placeholder: "App ID",
label: "App ID"
}],
[:subdomain, {
placeholder: "Access Token",
label: "Access Token"
}]... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/notification_services/hubot_service.rb | Ruby | mit | 4,272 | main | 860 | # frozen_string_literal: true
module NotificationServices
class HubotService < NotificationService
LABEL = "hubot"
FIELDS += [
[:api_token, {
placeholder: "http://hubot.example.org:8080/hubot/say",
label: "Hubot URL"
}],
[:room_id, {
placeholder: "#dev",
labe... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/notification_services/webhook_service.rb | Ruby | mit | 4,272 | main | 743 | # frozen_string_literal: true
module NotificationServices
class WebhookService < NotificationService
LABEL = "webhook"
FIELDS = [
[:api_token, {
placeholder: "URL to receive a POST request when an error occurs",
label: "URL"
}]
]
def check_params
if FIELDS.detect { ... |
github | errbit/errbit | https://github.com/errbit/errbit | app/models/notification_services/campfire_service.rb | Ruby | mit | 4,272 | main | 1,113 | # frozen_string_literal: true
module NotificationServices
class CampfireService < NotificationService
LABEL = "campfire"
FIELDS += [
[:subdomain, {
label: "Subdomain",
placeholder: "subdomain from http://{{subdomain}}.campfirenow.com"
}],
[:api_token, {
label: "API T... |
github | errbit/errbit | https://github.com/errbit/errbit | app/lib/configurator.rb | Ruby | mit | 4,272 | main | 2,083 | # frozen_string_literal: true
# Configurator maps lists of environment variables to names that you define in
# order to provide a consistent way to use configuration throughout your
# application
class Configurator
# Run the configurator and return the processed values
#
# @example Simple mapping
# ENV['BAR'... |
github | errbit/errbit | https://github.com/errbit/errbit | app/lib/hoptoad.rb | Ruby | mit | 4,272 | main | 643 | # frozen_string_literal: true
require_relative "hoptoad/v2"
module Hoptoad
class ApiVersionError < StandardError
def initialize
super("Wrong API Version: Expecting 2.0, 2.1, 2.2, 2.3 or 2.4")
end
end
class << self
def parse_xml!(xml)
parsed = ActiveSupport::XmlMini.backend.parse(xml)["n... |
github | errbit/errbit | https://github.com/errbit/errbit | app/lib/sparklines.rb | Ruby | mit | 4,272 | main | 318 | # frozen_string_literal: true
module Sparklines
class << self
def for_relative_percentages(array_of_relative_percentages)
bars = array_of_relative_percentages.map do |percent|
"<i style='height:#{percent}%'></i>"
end.join
"<div class='spark'>#{bars}</div>".html_safe
end
end
end |
github | errbit/errbit | https://github.com/errbit/errbit | app/lib/hoptoad/v2.rb | Ruby | mit | 4,272 | main | 2,216 | # frozen_string_literal: true
module Hoptoad
module V2
def self.process_notice(parsed)
for_errbit_api(
normalize(
rekey(parsed)
)
)
end
private
def self.rekey(node)
case node
when Hash
if node.key?("var") && node.key?("key")
{norma... |
github | errbit/errbit | https://github.com/errbit/errbit | app/lib/errbit/version.rb | Ruby | mit | 4,272 | main | 550 | # frozen_string_literal: true
module Errbit
class Version
def initialize(ver, dev = false)
@version = ver
@dev = dev
end
def full_version
full = [@version]
if @dev
full << "dev"
full << source_version
end
full.compact.join("-")
end
def source_... |
github | errbit/errbit | https://github.com/errbit/errbit | app/lib/airbrake_api/v3/notice_parser.rb | Ruby | mit | 4,272 | main | 2,525 | # frozen_string_literal: true
module AirbrakeApi
module V3
class NoticeParser
class ParamsError < StandardError
end
attr_reader :params, :error
def initialize(params = {})
@params = params.is_a?(ActionController::Parameters) ? params.to_unsafe_h : params
end
def att... |
github | errbit/errbit | https://github.com/errbit/errbit | db/seeds.rb | Ruby | mit | 4,272 | main | 1,185 | # frozen_string_literal: true
require "securerandom"
puts "Seeding database"
puts "-------------------------------"
# Create an initial Admin User
admin_username = ENV["ERRBIT_ADMIN_USER"] || "errbit"
def admin_email
return "admin@example.com" if heroku_pr_review_app?
ENV["ERRBIT_ADMIN_EMAIL"] || "errbit@#{Err... |
github | errbit/errbit | https://github.com/errbit/errbit | config/boot.rb | Ruby | mit | 4,272 | main | 238 | # frozen_string_literal: true
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
require "bundler/setup" # Set up gems listed in the Gemfile.
require "bootsnap/setup" # Speed up boot time by caching expensive operations. |
github | errbit/errbit | https://github.com/errbit/errbit | config/load.rb | Ruby | mit | 4,272 | main | 2,724 | # frozen_string_literal: true
# load default ENV values (without overwriting any existing value)
Dotenv.load(".env.default")
require_relative "../app/lib/configurator"
# map config keys to environment variables
#
# We use the first non-nil environment variable in the list. If the last array
# element is a proc, it r... |
github | errbit/errbit | https://github.com/errbit/errbit | config/environment.rb | Ruby | mit | 4,272 | main | 542 | # frozen_string_literal: true
# Load the Rails application.
require_relative "application"
# Load up Errbit::Config with values from the environment
require Rails.root.join("config/load")
case Errbit::Config.log_location
when "STDOUT"
# Skip. This is rails default behavior
when "Syslog::Logger"
require "syslog/l... |
github | errbit/errbit | https://github.com/errbit/errbit | config/mongo.rb | Ruby | mit | 4,272 | main | 445 | # frozen_string_literal: true
# log_level = "info"
#
# logger = Logger.const_get log_level.upcase
#
# Mongoid.logger.level = logger
# Mongo::Logger.level = logger
Mongoid.configure do |config|
uri = if Errbit::Config.mongo_url == "mongodb://localhost"
"mongodb://localhost/errbit_#{Rails.env}"
else
Errbit:... |
github | errbit/errbit | https://github.com/errbit/errbit | config/ci.rb | Ruby | mit | 4,272 | main | 724 | # frozen_string_literal: true
# Run using bin/ci
CI.run do
step "Setup", "bin/setup --skip-server"
step "Style: Ruby", "bin/rubocop"
step "Security: Gem audit", "bin/bundler-audit"
step "Security: Importmap vulnerability audit", "bin/importmap audit"
step "Security: Brakeman code analysis", "bin/brakeman ... |
github | errbit/errbit | https://github.com/errbit/errbit | config/importmap.rb | Ruby | mit | 4,272 | main | 411 | # frozen_string_literal: true
# Pin npm packages by running ./bin/importmap
# Enable integrity calculation globally
enable_integrity!
pin "application"
pin "@hotwired/stimulus", to: "stimulus.min.js"
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
pin_all_from "app/javascript/controllers", under: "contr... |
github | errbit/errbit | https://github.com/errbit/errbit | config/application.rb | Ruby | mit | 4,272 | main | 2,507 | # frozen_string_literal: true
require_relative "boot"
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
# require "active_record/railtie"
# require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
# require "action_ma... |
github | errbit/errbit | https://github.com/errbit/errbit | config/puma.rb | Ruby | mit | 4,272 | main | 1,953 | # frozen_string_literal: true
# This configuration file will be evaluated by Puma. The top-level methods that
# are invoked here are part of Puma's configuration DSL. For more information
# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.
#
# Puma starts a configurable number of processes (wo... |
github | errbit/errbit | https://github.com/errbit/errbit | config/routes.rb | Ruby | mit | 4,272 | main | 2,376 | # frozen_string_literal: true
Rails.application.routes.draw do
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
# Can be used by load balancers and uptime monitors to verify that the app is live.
get "up" => "rails/health#show", :as => :rails_health_check
devi... |
github | errbit/errbit | https://github.com/errbit/errbit | config/initializers/action_mailer.rb | Ruby | mit | 4,272 | main | 1,224 | # frozen_string_literal: true
# Set SMTP settings if given.
if Errbit::Config.email_delivery_method == :smtp
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: Errbit::Config.smtp_address,
port: Errbit::Config.smtp_port,
authentication: Errbit::Config.smtp_authenti... |
github | errbit/errbit | https://github.com/errbit/errbit | config/initializers/filter_parameter_logging.rb | Ruby | mit | 4,272 | main | 499 | # frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file.
# Use this to limit dissemination of sensitive information.
# See the ActiveSupport::ParameterFilter documentation for ... |
github | errbit/errbit | https://github.com/errbit/errbit | config/initializers/wrap_parameters.rb | Ruby | mit | 4,272 | main | 370 | # frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_con... |
github | errbit/errbit | https://github.com/errbit/errbit | config/initializers/deprecations.rb | Ruby | mit | 4,272 | main | 2,173 | # frozen_string_literal: true
deprecator = ActiveSupport::Deprecation.new(nil, "Errbit")
if ENV["USER_GEMFILE"].present?
# Make it error in v0.11.0 release and remove in v0.12.0
deprecator.warn(
"ENV['USER_GEMFILE'] support is removed and has no effect in Errbit v0.10.0. " \
"Remove it from configuration.... |
github | errbit/errbit | https://github.com/errbit/errbit | config/initializers/devise.rb | Ruby | mit | 4,272 | main | 16,468 | # frozen_string_literal: true
# Assuming you have not yet modified this file, each configuration option below
# is set to its default value. Note that some are commented out while others
# are not: uncommented lines are intended to protect your configuration from
# breaking changes in upgrades (i.e., in the event that... |
github | errbit/errbit | https://github.com/errbit/errbit | config/initializers/hoptoad.rb | Ruby | mit | 4,272 | main | 1,102 | # frozen_string_literal: true
# Override the 'hoptoad_notifier' gem's 'send_notice' method for internal errors.
# Find or create a 'Self.Errbit' app, and save the error internally
# unless errors should be sent to a different Errbit instance.
HoptoadNotifier.module_eval do
class << self
private def send_notice(n... |
github | errbit/errbit | https://github.com/errbit/errbit | config/initializers/assets.rb | Ruby | mit | 4,272 | main | 327 | # frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = "1.0"
# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.image... |
github | errbit/errbit | https://github.com/errbit/errbit | config/initializers/content_security_policy.rb | Ruby | mit | 4,272 | main | 1,363 | # frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Define an application-wide content security policy.
# See the Securing Rails Applications Guide for more information:
# https://guides.rubyonrails.org/security.html#content-security-policy-header
# Rails.application.configure... |
github | errbit/errbit | https://github.com/errbit/errbit | config/initializers/inflections.rb | Ruby | mit | 4,272 | main | 680 | # frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections
# are locale specific, and you may define rules for as many different
# locales as you wish. All of these examples are active by default:
# ActiveSupport::Inflec... |
github | errbit/errbit | https://github.com/errbit/errbit | config/initializers/hash.rb | Ruby | mit | 4,272 | main | 584 | # frozen_string_literal: true
class Hash
# Apply a block to hash, and recursively apply that block
# to each sub-hash or +types+.
#
# h = {:a=>1, :b=>{:b1=>1, :b2=>2}}
# g = h.recurse{|h| h.inject({}){|h,(k,v)| h[k.to_s] = v; h} }
# g #=> {"a"=>1, "b"=>{"b1"=>1, "b2"=>2}}
#
def recurse(*types, &... |
github | errbit/errbit | https://github.com/errbit/errbit | config/environments/development.rb | Ruby | mit | 4,272 | main | 2,542 | # frozen_string_literal: true
require "active_support/core_ext/integer/time"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Make code changes take effect immediately without server restart.
config.enable_reloading = true
# Do not eager lo... |
github | errbit/errbit | https://github.com/errbit/errbit | config/environments/test.rb | Ruby | mit | 4,272 | main | 2,225 | # frozen_string_literal: true
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
Rails.applic... |
github | errbit/errbit | https://github.com/errbit/errbit | config/environments/production.rb | Ruby | mit | 4,272 | main | 3,358 | # frozen_string_literal: true
require "active_support/core_ext/integer/time"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.enable_reloading = false
# Eager load code on boot for better perfor... |
github | grosser/parallel | https://github.com/grosser/parallel | Gemfile | Ruby | mit | 4,248 | master | 362 | # frozen_string_literal: true
source "https://rubygems.org"
gemspec
gem 'bump'
gem 'rake'
gem 'rspec'
gem 'activerecord'
gem 'ruby-progressbar'
gem 'rspec-rerun'
gem 'rspec-legacy_formatters'
gem 'rubocop'
gem 'rubocop-rake'
gem 'rubocop-rspec'
gem 'benchmark'
gem 'logger'
gem 'mutex_m'
gem 'base64'
gem 'bigdecimal'
... |
github | grosser/parallel | https://github.com/grosser/parallel | parallel.gemspec | Ruby | mit | 4,248 | master | 828 | # frozen_string_literal: true
name = "parallel"
$LOAD_PATH << File.expand_path('lib', __dir__)
require "#{name}/version"
Gem::Specification.new name, Parallel::VERSION do |s|
s.summary = "Run any kind of code in parallel processes"
s.authors = ["Michael Grosser"]
s.email = "michael@grosser.it"
s.homepage = "ht... |
github | grosser/parallel | https://github.com/grosser/parallel | Rakefile | Ruby | mit | 4,248 | master | 312 | # frozen_string_literal: true
require 'bundler/setup'
require 'bundler/gem_tasks'
require 'bump/tasks'
require "rspec/core/rake_task"
require 'rspec-rerun/tasks'
task default: ["spec", "rubocop"]
desc "Run tests"
task spec: "rspec-rerun:spec"
desc "Run rubocop"
task :rubocop do
sh "rubocop --parallel"
end |
github | grosser/parallel | https://github.com/grosser/parallel | spec/parallel_spec.rb | Ruby | mit | 4,248 | master | 25,301 | # frozen_string_literal: true
require 'spec_helper'
describe Parallel do
worker_types = ["threads"]
worker_types << "processes" if Process.respond_to?(:fork)
worker_types << "ractors" if defined?(Ractor)
def time_taken
t = Time.now.to_f
yield
RUBY_ENGINE == "jruby" ? 0 : Time.now.to_f - t # jruby ... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/spec_helper.rb | Ruby | mit | 4,248 | master | 402 | # frozen_string_literal: true
require 'parallel'
require 'benchmark'
require 'timeout'
RSpec.configure do |config|
config.expect_with(:rspec) { |c| c.syntax = :should }
config.mock_with(:rspec) { |c| c.syntax = :should }
config.around { |example| Timeout.timeout(30, &example) }
config.include(
Module.new d... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/parallel/serializer_spec.rb | Ruby | mit | 4,248 | master | 3,520 | # frozen_string_literal: true
require 'spec_helper'
require 'json'
describe Parallel::Serializer do
describe Parallel::Serializer::Hmac do
let(:serializer) { described_class.new }
def with_pipe
read, write = IO.pipe
yield read, write
ensure
read.close unless read.closed?
write.cl... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/map_with_ar.rb | Ruby | mit | 4,248 | master | 815 | # frozen_string_literal: true
require './spec/cases/helper'
require "active_record"
database = "parallel_with_ar_test"
`mysql #{database} -e '' || mysql -e 'create database #{database}'`
ActiveRecord::Schema.verbose = false
ActiveRecord::Base.establish_connection(
adapter: "mysql2",
database: database
)
class Us... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/with_break.rb | Ruby | mit | 4,248 | master | 840 | # frozen_string_literal: true
require './spec/cases/helper'
$stdout.sync = true # otherwise results can go weird...
method = ENV.fetch('METHOD')
in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}"
worker_size = (ENV['WORKER_SIZE'] || 4).to_i
ARGV.freeze # make ractor happy
class Callback
def self.call(x)
$stdou... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/progress.rb | Ruby | mit | 4,248 | master | 203 | # frozen_string_literal: true
require './spec/cases/helper'
title = (ENV["TITLE"] == "true" ? true : "Doing stuff")
Parallel.map(1..10, progress: title) do
sleep 1 if $stdout.tty? # for debugging
end |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/exception_raised_in_process.rb | Ruby | mit | 4,248 | master | 328 | # frozen_string_literal: true
require './spec/cases/helper'
begin
Parallel.each([1]) { raise StandardError } # rubocop:disable Lint/UnreachableLoop
rescue Parallel::DeadWorker
puts "No, DEAD worker found"
rescue Exception # rubocop:disable Lint/RescueException
puts "Yep, rescued the exception"
else
puts "WHOOO... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/timeout_in_threads.rb | Ruby | mit | 4,248 | master | 217 | # frozen_string_literal: true
require './spec/cases/helper'
require 'timeout'
Parallel.each([1], in_threads: 1) do |_i|
Timeout.timeout(0.1) { sleep 0.2 }
rescue Timeout::Error
puts "OK"
else
puts "BROKEN"
end |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/parallel_start_and_kill.rb | Ruby | mit | 4,248 | master | 480 | # frozen_string_literal: true
require './spec/cases/helper'
method = case ARGV[0]
when "PROCESS" then :in_processes
when "THREAD" then :in_threads
else raise "Learn to use this!"
end
options = {}
options[:count] = 2
if ARGV.length > 1
options[:interrupt_signal] = ARGV[1].to_s
trap('SIGI... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/parallel_break_with_undumpable_cause.rb | Ruby | mit | 4,248 | master | 439 | # frozen_string_literal: true
require './spec/cases/helper'
class UndumpableCauseError < StandardError
def initialize
super("bad")
@binding = binding # can't be dumped when it is the cause
end
end
begin
x = Parallel.in_processes(2) do
raise UndumpableCauseError
rescue StandardError
raise Paral... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/eof_in_process.rb | Ruby | mit | 4,248 | master | 205 | # frozen_string_literal: true
require './spec/cases/helper'
begin
Parallel.map([1]) { raise EOFError } # rubocop:disable Lint/UnreachableLoop
rescue EOFError
puts 'Yep, EOF'
else
puts 'WHOOOPS'
end |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/map_with_killed_worker_before_write.rb | Ruby | mit | 4,248 | master | 375 | # frozen_string_literal: true
require './spec/cases/helper'
Parallel::Worker.class_eval do
alias_method :work_without_kill, :work
def work(*args)
Process.kill("SIGKILL", pid)
sleep 0.5
work_without_kill(*args)
end
end
begin
Parallel.map([1, 2, 3]) do |_x, _i|
Process.kill("SIGKILL", Process.pi... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/with_queue.rb | Ruby | mit | 4,248 | master | 443 | # frozen_string_literal: true
require './spec/cases/helper'
type = :"in_#{ARGV.fetch(0)}"
class Callback
def self.call(x)
"ITEM-#{x}"
end
end
queue = Queue.new
Thread.new do
sleep 0.2
queue.push 1
queue.push 2
queue.push 3
queue.push Parallel::Stop
end
if type == :in_ractors
puts(Parallel.map(qu... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/parallel_kill.rb | Ruby | mit | 4,248 | master | 305 | # frozen_string_literal: true
require './spec/cases/helper'
results = Parallel.map([1, 2, 3]) do |x|
case x
when 1 # -> stop all sub-processes, killing them instantly
sleep 0.1
puts "DEAD"
raise Parallel::Kill
when 3
sleep 10
else
x
end
end
puts "Works #{results.inspect}" |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/parallel_break_better_errors.rb | Ruby | mit | 4,248 | master | 545 | # frozen_string_literal: true
require './spec/cases/helper'
require 'stringio'
class MyException < StandardError
def initialize(object)
super()
@object = object
end
end
begin
Parallel.in_processes(2) do
ex = Parallel::Break.new
# better_errors sets an instance variable that contains an array of ... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/any_false.rb | Ruby | mit | 4,248 | master | 532 | # frozen_string_literal: true
require './spec/cases/helper'
$stdout.sync = true # otherwise results can go weird...
results = []
[{ in_processes: 2 }, { in_threads: 2 }, { in_threads: 0 }].each do |options|
x = [nil, nil, nil, nil, nil, nil, nil, nil]
results << Parallel.any?(x, options) do |y|
y
end
x =... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/with_exception_before_finish.rb | Ruby | mit | 4,248 | master | 711 | # frozen_string_literal: true
require './spec/cases/helper'
method = ENV.fetch('METHOD')
in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}"
class ParallelTestError < StandardError
end
class Callback
def self.call(x)
$stdout.sync = true
if x != 3
sleep 0.2
raise ParallelTestError
end
pri... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/with_worker_number.rb | Ruby | mit | 4,248 | master | 279 | # frozen_string_literal: true
require './spec/cases/helper'
method = ENV.fetch('METHOD')
in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}"
Parallel.public_send(method, 1..20, in_worker_type => 4) do
sleep 0.02 # so all workers get started
print Parallel.worker_number
end |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/parallel_raise_undumpable.rb | Ruby | mit | 4,248 | master | 374 | # frozen_string_literal: true
require './spec/cases/helper'
require 'stringio'
class MyException < StandardError
def initialize(object)
super()
@object = object
end
end
begin
Parallel.in_processes(2) do
raise MyException, StringIO.new
end
puts "NOTHING WAS RAISED"
rescue StandardError
puts $!.... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/any_true.rb | Ruby | mit | 4,248 | master | 451 | # frozen_string_literal: true
require './spec/cases/helper'
$stdout.sync = true # otherwise results can go weird...
results = []
[{ in_processes: 2 }, { in_threads: 2 }, { in_threads: 0 }].each do |options|
x = [nil, nil, nil, nil, 42, nil, nil, nil]
results << Parallel.any?(x, options) do |y|
y
end
x = ... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/each.rb | Ruby | mit | 4,248 | master | 222 | # frozen_string_literal: true
require './spec/cases/helper'
$stdout.sync = true # otherwise results can go weird...
x = ['a', 'b', 'c', 'd']
result = Parallel.each(x) do |y|
sleep 0.1 if y == 'a'
end
print result * ' ' |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/progress_with_options.rb | Ruby | mit | 4,248 | master | 647 | # frozen_string_literal: true
require './spec/cases/helper'
# ruby-progressbar ignores the format string you give it
# unless the output is a TTY. When running in the test,
# the output is not a TTY, so we cannot test that the format
# string you pass overrides parallel's default. So, we pretend
# that stdout is a T... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/helper.rb | Ruby | mit | 4,248 | master | 468 | # frozen_string_literal: true
require 'bundler/setup'
require 'parallel'
def process_diff
called_from = caller(1)[0].split(":").first # forks will have the source file in their name
cmd = "ps uxw|grep #{called_from}|wc -l"
processes_before = `#{cmd}`.to_i
yield
sleep 0.5
processes_after = `#{cmd}`.to_i... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/map_worker_number_isolation.rb | Ruby | mit | 4,248 | master | 228 | # frozen_string_literal: true
require './spec/cases/helper'
process_diff do
result = Parallel.map([1, 2, 3, 4], in_processes: 2, isolation: true) do |_i|
Parallel.worker_number
end
puts result.uniq.sort.join(',')
end |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/parallel_map_complex_objects.rb | Ruby | mit | 4,248 | master | 264 | # frozen_string_literal: true
require './spec/cases/helper'
object = ["\nasd#{File.read('Gemfile')}--#{File.read('Rakefile')}" * 100, 12_345, { b: :a }]
result = Parallel.map([1, 2]) do |_x|
object
end
print 'YES' if result.inspect == [object, object].inspect |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/with_exception_in_finish.rb | Ruby | mit | 4,248 | master | 824 | # frozen_string_literal: true
require './spec/cases/helper'
$stdout.sync = true
method = ENV.fetch('METHOD')
in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}"
class ParallelTestError < StandardError
end
class Callback
def self.call(x)
$stdout.sync = true
print x
sleep 0.2 # let everyone start and prin... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/with_exception_in_start.rb | Ruby | mit | 4,248 | master | 841 | # frozen_string_literal: true
require './spec/cases/helper'
method = ENV.fetch('METHOD')
in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}"
class ParallelTestError < StandardError
end
class Callback
def self.call(x)
$stdout.sync = true
print x
sleep 0.2 # so now no work gets queued before exception is ... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/synchronizes_start_and_finish.rb | Ruby | mit | 4,248 | master | 348 | # frozen_string_literal: true
require './spec/cases/helper'
start = lambda { |item, _index|
print item * 5
sleep rand * 0.2
puts item * 5
}
finish = lambda { |_item, _index, result|
print result * 5
sleep rand * 0.2
puts result * 5
}
Parallel.map(['a', 'b', 'c'], start: start, finish: finish) do |i|
slee... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/with_lambda.rb | Ruby | mit | 4,248 | master | 428 | # frozen_string_literal: true
require './spec/cases/helper'
$stdout.sync = true
type = :"in_#{ARGV.fetch(0)}"
all = [3, 2, 1]
produce = -> { all.pop || Parallel::Stop }
class Callback
def self.call(x)
$stdout.sync = true
"ITEM-#{x}"
end
end
if type == :in_ractors
puts(Parallel.map(produce, type => 2, r... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/double_interrupt.rb | Ruby | mit | 4,248 | master | 222 | # frozen_string_literal: true
require './spec/cases/helper'
Signal.trap :SIGINT do
sleep 0.5
puts "YES"
exit 0
end
Parallel.map(Array.new(20), in_processes: 2) do
sleep 10
puts "I should be killed earlier"
end |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/all_false.rb | Ruby | mit | 4,248 | master | 458 | # frozen_string_literal: true
require './spec/cases/helper'
$stdout.sync = true # otherwise results can go weird...
results = []
[{ in_processes: 2 }, { in_threads: 2 }, { in_threads: 0 }].each do |options|
x = [nil, nil, nil, nil, nil, nil, nil, nil]
results << Parallel.all?(x, options) do |y|
y
end
x =... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/no_dump_with_each.rb | Ruby | mit | 4,248 | master | 309 | # frozen_string_literal: true
require './spec/cases/helper'
class NotDumpable
def marshal_dump
raise "NOOOO"
end
def to_s
'not dumpable'
end
end
Parallel.each([1]) do
print 'no dump for result'
NotDumpable.new
end
Parallel.each([NotDumpable.new]) do
print 'no dump for each'
1
end |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/all_true.rb | Ruby | mit | 4,248 | master | 551 | # frozen_string_literal: true
require './spec/cases/helper'
$stdout.sync = true # otherwise results can go weird...
results = []
[{ in_processes: 2 }, { in_threads: 2 }, { in_threads: 0 }].each do |options|
x = [nil, nil, nil, nil, nil, nil, nil, nil]
results << Parallel.all?(x, options, &:nil?)
x = [42, 42, 4... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/with_exception_in_start_before_finish.rb | Ruby | mit | 4,248 | master | 831 | # frozen_string_literal: true
require './spec/cases/helper'
method = ENV.fetch('METHOD')
in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}"
$stdout.sync = true
class ParallelTestError < StandardError
end
class Callback
def self.call(x)
$stdout.sync = true
puts "call #{x}"
x
end
end
begin
start = l... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/count_open_pipes.rb | Ruby | mit | 4,248 | master | 550 | # frozen_string_literal: true
require './spec/cases/helper'
count = ->(*) { Dir.children("/dev/fd").size }
if ENV["SELF_TEST"]
# verify that count detects newly opened pipes
create = 5
before = count.call
pipes = create.times.map { IO.pipe }
after = count.call
expected = before + (create * 2)
raise "expe... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/with_break_before_finish.rb | Ruby | mit | 4,248 | master | 698 | # frozen_string_literal: true
require './spec/cases/helper'
method = ENV.fetch('METHOD')
in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}"
$stdout.sync = true
class Callback
def self.call(x)
$stdout.sync = true
sleep 0.1 # let workers start
raise Parallel::Break if x == 1
sleep 0.2
print x
... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/finish_in_order.rb | Ruby | mit | 4,248 | master | 674 | # frozen_string_literal: true
require './spec/cases/helper'
class Callback
def self.call(item)
sleep rand * 0.01
item.is_a?(Numeric) ? "F#{item}" : item
end
end
method = ENV.fetch('METHOD')
in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}"
$stdout.sync = true
items = [nil, false, 2, 3, 4]
finish = ->(i... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/progress_with_finish.rb | Ruby | mit | 4,248 | master | 247 | # frozen_string_literal: true
require './spec/cases/helper'
sum = 0
finish = ->(_item, _index, result) { sum += result }
Parallel.map(1..10, progress: "Doing stuff", finish: finish) do
sleep 1 if $stdout.tty? # for debugging
2
end
puts sum |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/exit_in_process.rb | Ruby | mit | 4,248 | master | 208 | # frozen_string_literal: true
require './spec/cases/helper'
begin
Parallel.map([1]) { exit } # rubocop:disable Lint/UnreachableLoop
rescue Parallel::DeadWorker
puts "Yep, DEAD"
else
puts "WHOOOPS"
end |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/with_exception.rb | Ruby | mit | 4,248 | master | 837 | # frozen_string_literal: true
require './spec/cases/helper'
$stdout.sync = true # otherwise results can go weird...
method = ENV.fetch('METHOD')
in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}"
worker_size = (ENV['WORKER_SIZE'] || 4).to_i
class ParallelTestError < StandardError
end
class Callback
def self.call(x... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/map_with_ractor.rb | Ruby | mit | 4,248 | master | 249 | # frozen_string_literal: true
require './spec/cases/helper'
class Callback
def self.call(arg)
"#{arg}x"
end
end
result = Parallel.map(ENV['INPUT'].chars, in_ractors: Integer(ENV["COUNT"] || 2), ractor: [Callback, :call])
print result * '' |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/each_with_ar_sqlite.rb | Ruby | mit | 4,248 | master | 1,144 | # frozen_string_literal: true
require './spec/cases/helper'
require "logger"
require "active_record"
require "sqlite3"
require "tempfile"
$stdout.sync = true
in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}"
Tempfile.create("db") do |temp|
ActiveRecord::Schema.verbose = false
ActiveRecord::Base.establish_connecti... |
github | grosser/parallel | https://github.com/grosser/parallel | spec/cases/profile_memory.rb | Ruby | mit | 4,248 | master | 825 | # frozen_string_literal: true
def count_objects
old = Hash.new(0)
cur = Hash.new(0)
GC.start
ObjectSpace.each_object { |o| old[o.class] += 1 }
yield
GC.start
GC.start
ObjectSpace.each_object { |o| cur[o.class] += 1 }
cur.to_h { |k, v| [k, v - old[k]] }.reject { |_k, v| v == 0 }
end
class Callback
d... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.