scheduled_job 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Rakefile +10 -0
- data/db/connect.rb +15 -0
- data/db/schema.rb +14 -0
- data/lib/scheduled_job/version.rb +1 -1
- data/lib/scheduled_job.rb +7 -0
- data/lib/tasks/database.rake +4 -0
- data/lib/tasks/jobs.rb +28 -0
- data/scheduled_job.gemspec +1 -0
- data/spec/lib/scheduled_job_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e237cb5535336997a5bc97f2ccc0092f038ce5c
|
4
|
+
data.tar.gz: dd0f0331da06bf19651c16b3216fa2f29fb778a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c581219617e217ca776697a98fac4b82b6369a1cb317b90c9f2509c148d1ce599173d7f7443f4b0af65324bfe0fb2ae39ddebeae3157c9c9264c9c22ff884cd1
|
7
|
+
data.tar.gz: 8f7718d33ca84cad2ae07a12705b8781a14d01230b1e3f5ac96b7806ca2a477b140ec480e0ec7d99e939d4312ec4619450dd7503f336799c1f74d361d18bac8c
|
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require 'rspec/core/rake_task'
|
3
3
|
|
4
|
+
require_relative 'db/connect'
|
5
|
+
require 'scheduled_job'
|
6
|
+
|
4
7
|
RSpec::Core::RakeTask.new('spec')
|
8
|
+
Dir[File.dirname(__FILE__) + '/lib/tasks/**/*.rake'].each { |file| import file }
|
5
9
|
|
6
10
|
task :default => :spec
|
11
|
+
|
12
|
+
desc "console"
|
13
|
+
task :console => :dbconnect do
|
14
|
+
require 'pry'
|
15
|
+
binding.pry # rubocop:disable Lint/Debugger
|
16
|
+
end
|
data/db/connect.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module Db
|
4
|
+
class Connect
|
5
|
+
def self.init
|
6
|
+
ActiveRecord::Base.establish_connection(
|
7
|
+
:adapter => "sqlite3",
|
8
|
+
:dbfile => ":memory:",
|
9
|
+
:database => "scheduled_job"
|
10
|
+
)
|
11
|
+
|
12
|
+
require_relative 'schema'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/db/schema.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
create_table :delayed_jobs, :force => true do |table|
|
3
|
+
table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
|
4
|
+
table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
|
5
|
+
table.text :handler # YAML-encoded string of the object that will do work
|
6
|
+
table.text :last_error # reason for last failure (See Note below)
|
7
|
+
table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
|
8
|
+
table.datetime :locked_at # Set when a client is working on this object
|
9
|
+
table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
|
10
|
+
table.string :locked_by # Who is working on this object (if locked)
|
11
|
+
table.string :queue # The name of the queue this job is in
|
12
|
+
table.timestamps
|
13
|
+
end
|
14
|
+
end
|
data/lib/scheduled_job.rb
CHANGED
@@ -2,6 +2,7 @@ require "scheduled_job/version"
|
|
2
2
|
require 'logger'
|
3
3
|
require 'delayed_job'
|
4
4
|
require 'delayed_job_active_record'
|
5
|
+
require File.dirname(__FILE__) + '/tasks/jobs.rb'
|
5
6
|
|
6
7
|
module ScheduledJob
|
7
8
|
class << self
|
@@ -28,9 +29,15 @@ module ScheduledJob
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def self.included(base)
|
32
|
+
@classes ||= []
|
33
|
+
@classes << base.name.constantize
|
31
34
|
base.extend ScheduledJobClassMethods
|
32
35
|
end
|
33
36
|
|
37
|
+
def self.classes
|
38
|
+
@classes
|
39
|
+
end
|
40
|
+
|
34
41
|
def before(job)
|
35
42
|
callback = ScheduledJob.config.before_callback
|
36
43
|
callback.call(job, self) if callback
|
data/lib/tasks/jobs.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
module ScheduledJob
|
4
|
+
class Job
|
5
|
+
include Rake::DSL if defined? Rake::DSL
|
6
|
+
|
7
|
+
def install_tasks
|
8
|
+
def check_schedule_job(job)
|
9
|
+
if job.respond_to?(:time_to_recur)
|
10
|
+
job.schedule_job
|
11
|
+
else
|
12
|
+
job.descendants.each { |j| check_schedule_job(j) }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
namespace:jobs do
|
17
|
+
desc "Will schedule all scheduled jobs"
|
18
|
+
task :reschedule => :environment do
|
19
|
+
ScheduledJob.classes.each do |job|
|
20
|
+
check_schedule_job(job)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
ScheduledJob::Job.new.install_tasks
|
data/scheduled_job.gemspec
CHANGED
@@ -126,7 +126,7 @@ describe ScheduledJob do
|
|
126
126
|
UnderTest.schedule_job job
|
127
127
|
end
|
128
128
|
|
129
|
-
|
129
|
+
it 'doesnt find substring jobs as existing' do
|
130
130
|
UnderTest.schedule_job
|
131
131
|
Test.schedule_job
|
132
132
|
expect(Delayed::Job.count).to eq(2)
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scheduled_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CallumD
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-
|
14
|
+
date: 2015-02-02 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: delayed_job
|
@@ -111,6 +111,20 @@ dependencies:
|
|
111
111
|
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '0'
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: sqlite3
|
116
|
+
requirement: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - "~>"
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 1.3.10
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - "~>"
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: 1.3.10
|
114
128
|
description: By including the scheduled job module in a delayed job you can specify
|
115
129
|
when you would like the job to run again. Currently this is intented to be used
|
116
130
|
with the active record back end this may change in future.
|
@@ -131,8 +145,12 @@ files:
|
|
131
145
|
- LICENSE.txt
|
132
146
|
- README.md
|
133
147
|
- Rakefile
|
148
|
+
- db/connect.rb
|
149
|
+
- db/schema.rb
|
134
150
|
- lib/scheduled_job.rb
|
135
151
|
- lib/scheduled_job/version.rb
|
152
|
+
- lib/tasks/database.rake
|
153
|
+
- lib/tasks/jobs.rb
|
136
154
|
- pry.rb
|
137
155
|
- scheduled_job.gemspec
|
138
156
|
- scheduled_job.rconf
|