delayed_job_nobrainer 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +14 -0
- data/LICENSE.md +20 -0
- data/README.md +42 -0
- data/delayed_job_nobrainer.gemspec +14 -0
- data/lib/delayed/backend/nobrainer.rb +92 -0
- data/lib/delayed_job_nobrainer.rb +6 -0
- data/lib/rake_tasks.rb +5 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4fcebd5227a61d751af00fc39e921e839d3216dd
|
4
|
+
data.tar.gz: 038b6be79c0485d176dc543e73a06b143a4c1125
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d17b4177c27ffd7a834434fdb3031534caa95005909e1a6e0ba6292cd765232974025500ac8d7471ab0ecd63978963b9522a23eee7a97752d1e251a82694663
|
7
|
+
data.tar.gz: 3f0a43c0f86e28d92ffc1067b94c6d9608b7d7468fc058c915317a8469deb2c44f8cdc88d50a6373c40d98b8f4c09a549672f500aa0d6993272eee9f7589331b
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
## How to contribute
|
2
|
+
|
3
|
+
If you find what looks like a bug:
|
4
|
+
|
5
|
+
* Search the [mailing list](http://groups.google.com/group/delayed_job) to see if anyone else had the same issue.
|
6
|
+
* Check the [GitHub issue tracker](http://github.com/collectiveidea/delayed_job_active_record/issues/) to see if anyone else has reported issue.
|
7
|
+
* If you don't see anything, create an issue with information on how to reproduce it.
|
8
|
+
|
9
|
+
If you want to contribute an enhancement or a fix:
|
10
|
+
|
11
|
+
* Fork the project on github.
|
12
|
+
* Make your changes with tests.
|
13
|
+
* Commit the changes without making changes to the Rakefile or any other files that aren't related to your enhancement or fix
|
14
|
+
* Send a pull request.
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2005 Tobias Lütke
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOa AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SaALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
**If you're viewing this at https://github.com/collectiveidea/delayed_job_active_record,
|
2
|
+
you're reading the documentation for the master branch.
|
3
|
+
[View documentation for the latest release
|
4
|
+
(4.1.2).](https://github.com/collectiveidea/delayed_job_active_record/tree/v4.1.2)**
|
5
|
+
|
6
|
+
# DelayedJob ActiveRecord Backend
|
7
|
+
|
8
|
+
[](https://rubygems.org/gems/delayed_job_active_record)
|
9
|
+
[](https://travis-ci.org/collectiveidea/delayed_job_active_record)
|
10
|
+
[](https://gemnasium.com/collectiveidea/delayed_job_active_record)
|
11
|
+
[](https://codeclimate.com/github/collectiveidea/delayed_job_active_record)
|
12
|
+
[](https://coveralls.io/r/collectiveidea/delayed_job_active_record)
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add the gem to your Gemfile:
|
17
|
+
|
18
|
+
gem 'delayed_job_active_record'
|
19
|
+
|
20
|
+
Run `bundle install`.
|
21
|
+
|
22
|
+
If you're using Rails, run the generator to create the migration for the
|
23
|
+
delayed_job table.
|
24
|
+
|
25
|
+
rails g delayed_job:active_record
|
26
|
+
rake db:migrate
|
27
|
+
|
28
|
+
## Problems locking jobs
|
29
|
+
|
30
|
+
You can try using the legacy locking code. It is usually slower but works better for certain people.
|
31
|
+
|
32
|
+
Delayed::Backend::ActiveRecord.configuration.reserve_sql_strategy = :default_sql
|
33
|
+
|
34
|
+
## Upgrading from 2.x to 3.0.0
|
35
|
+
|
36
|
+
If you're upgrading from Delayed Job 2.x, run the upgrade generator to create a
|
37
|
+
migration to add a column to your delayed_jobs table.
|
38
|
+
|
39
|
+
rails g delayed_job:upgrade
|
40
|
+
rake db:migrate
|
41
|
+
|
42
|
+
That's it. Use [delayed_job as normal](http://github.com/collectiveidea/delayed_job).
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.add_dependency "nobrainer", [">= 0.32"]
|
3
|
+
spec.add_dependency "delayed_job", [">= 3.0", "< 5"]
|
4
|
+
spec.authors = ["Stefan Eilers"]
|
5
|
+
spec.description = "NoBrainer backend for Delayed::Job, based on delayed_job_active_record"
|
6
|
+
spec.email = ["se@intelligentmobiles.com"]
|
7
|
+
spec.files = %w(CONTRIBUTING.md LICENSE.md README.md delayed_job_nobrainer.gemspec) + Dir["lib/**/*.rb"]
|
8
|
+
spec.homepage = "http://intelligentmobiles.com"
|
9
|
+
spec.licenses = ["MIT"]
|
10
|
+
spec.name = "delayed_job_nobrainer"
|
11
|
+
spec.require_paths = ["lib"]
|
12
|
+
spec.summary = "NoBrainer backend for DelayedJob"
|
13
|
+
spec.version = "0.1.2"
|
14
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "nobrainer"
|
2
|
+
|
3
|
+
module Delayed
|
4
|
+
module Backend
|
5
|
+
module NoBrainer
|
6
|
+
# A job object that is persisted to the database.
|
7
|
+
# Contains the work object as a YAML field.
|
8
|
+
class Job
|
9
|
+
include ::NoBrainer::Document
|
10
|
+
include ::NoBrainer::Document::Timestamps
|
11
|
+
include Delayed::Backend::Base
|
12
|
+
|
13
|
+
cattr_accessor :default_queue
|
14
|
+
|
15
|
+
self.default_queue = "default"
|
16
|
+
|
17
|
+
field :priority, :type => Integer, :index => true
|
18
|
+
field :attempts, :type => Integer
|
19
|
+
field :handler, :type => Text
|
20
|
+
field :last_error, :type => String
|
21
|
+
field :run_at, :type => Time, :index => true
|
22
|
+
field :locked_at, :type => Time
|
23
|
+
field :locked_by, :type => String
|
24
|
+
field :failed_at, :type => Time
|
25
|
+
field :queue, :type => String
|
26
|
+
|
27
|
+
before_create do |o|
|
28
|
+
o.attempts = 0
|
29
|
+
o.priority ||= 0
|
30
|
+
o.queue ||= self.class.default_queue
|
31
|
+
o.run_at ||= Time.now
|
32
|
+
end
|
33
|
+
|
34
|
+
# Get the current time (GMT or local depending on DB)
|
35
|
+
# Note: This does not ping the DB to get the time, so all your clients
|
36
|
+
# must have syncronized clocks.
|
37
|
+
def self.db_time_now
|
38
|
+
if Time.zone
|
39
|
+
Time.zone.now
|
40
|
+
else
|
41
|
+
Time.now
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.clear_locks!(worker_name)
|
46
|
+
where(locked_by: worker_name).update_all(locked_by: nil, locked_at: nil)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.reserve(worker, max_run_time = Worker.max_run_time)
|
50
|
+
# Taken from Active Record
|
51
|
+
# where("(run_at <= ? AND (locked_at IS NULL OR locked_at < ?) OR locked_by = ?) AND failed_at IS NULL", db_time_now, db_time_now - max_run_time, worker_name)
|
52
|
+
# "priority >= ?", Worker.min_priority if Worker.min_priority
|
53
|
+
# "priority <= ?", Worker.max_priority) if Worker.max_priority
|
54
|
+
# where(queue: Worker.queues) if Worker.queues.any?
|
55
|
+
# order("priority ASC, run_at ASC") }
|
56
|
+
|
57
|
+
filter_hash = { :failed_at.defined => false, :run_at.le => db_time_now,
|
58
|
+
:or => [{:locked_at.defined => false},
|
59
|
+
{:locked_at.lt => db_time_now - max_run_time},
|
60
|
+
:locked_by => worker.name] }
|
61
|
+
filter_hash = filter_hash.merge({:priority.ge => Worker.min_priority}) if Worker.min_priority
|
62
|
+
filter_hash = filter_hash.merge({:priority.le => Worker.max_priority}) if Worker.max_priority
|
63
|
+
filter_hash = filter_hash.merge({:queue.in => Worker.queues}) if Worker.queues.any?
|
64
|
+
|
65
|
+
job = where(filter_hash).order_by(:priority => :asc).first
|
66
|
+
job.update(locked_at: Time.now, locked_by: worker.name) unless job.nil?
|
67
|
+
job
|
68
|
+
end
|
69
|
+
|
70
|
+
def error
|
71
|
+
unless instance_variable_defined?(:@error)
|
72
|
+
if last_error
|
73
|
+
backtrace = last_error.split("\n")
|
74
|
+
message = backtrace.shift
|
75
|
+
@error = Exception.new(message)
|
76
|
+
@error.set_backtrace(backtrace)
|
77
|
+
else
|
78
|
+
@error = nil
|
79
|
+
end
|
80
|
+
end
|
81
|
+
@error
|
82
|
+
end
|
83
|
+
|
84
|
+
def error=(error)
|
85
|
+
@error = error
|
86
|
+
self.last_error = "#{error.message}\n#{error.backtrace.join("\n")}"[0..250].gsub(/\s\w+\s*$/,'...') if self.respond_to?(:last_error=)
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/lib/rake_tasks.rb
ADDED
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: delayed_job_nobrainer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stefan Eilers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nobrainer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.32'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.32'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: delayed_job
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '5'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.0'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '5'
|
47
|
+
description: NoBrainer backend for Delayed::Job, based on delayed_job_active_record
|
48
|
+
email:
|
49
|
+
- se@intelligentmobiles.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- CONTRIBUTING.md
|
55
|
+
- LICENSE.md
|
56
|
+
- README.md
|
57
|
+
- delayed_job_nobrainer.gemspec
|
58
|
+
- lib/delayed/backend/nobrainer.rb
|
59
|
+
- lib/delayed_job_nobrainer.rb
|
60
|
+
- lib/rake_tasks.rb
|
61
|
+
homepage: http://intelligentmobiles.com
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.6.7
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: NoBrainer backend for DelayedJob
|
85
|
+
test_files: []
|
86
|
+
has_rdoc:
|