delayed_job_schedule 0.0.4
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/MIT-LICENSE +20 -0
- data/README.rdoc +26 -0
- data/lib/delayed/schedule.rb +44 -0
- data/lib/delayed_job_schedule.rb +4 -0
- data/lib/delayed_job_schedule/engine.rb +9 -0
- data/lib/delayed_job_schedule/version.rb +3 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 16370e85f28b4825501fdc212d80401c79c2a6d25014d52de91e83ba3d46ae90
|
4
|
+
data.tar.gz: 9fd10c42f82ac1d741be5386df345549ac564830baf9aadb83272ec26b458dae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ccc125281aea49e95db665e8499d11477a5c9ed19e2cdb353ee365613861746003eb8a3c7610a3b483c35ddb462bb5686b32bcaf72c578a3b4afd412729efa84
|
7
|
+
data.tar.gz: 56ea1d3f49c8a55732cfdd22d9c8fa790e5d2ed8766a5cf370b772dbd6ffb0287edd8009792a53ff11e9ae25cd44bd4fd9d645c5663406fcaaa6dd9e978fe292
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Georg Limbach
|
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 PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL 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.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= delayed_job_schedule
|
2
|
+
|
3
|
+
This gem provides a schedule plugin for delayed_job. The delayed_job[https://github.com/collectiveidea/delayed_job] worker will check after each loop for schedule tasks to do.
|
4
|
+
|
5
|
+
== Pro
|
6
|
+
* uses less memory than multiple workers for delayed_job and a scheduler (a.e. clockwork[https://github.com/tomykaira/clockwork])
|
7
|
+
|
8
|
+
== Contra
|
9
|
+
* you can only use time ranges
|
10
|
+
|
11
|
+
|
12
|
+
== Install
|
13
|
+
|
14
|
+
Add delayed_job_schedule to your Gemfile:
|
15
|
+
|
16
|
+
gem 'delayed_job_schedule', git: 'https://github.com/lichtbit/delayed_job_schedule.git'
|
17
|
+
|
18
|
+
Use it in your initializer:
|
19
|
+
|
20
|
+
Delayed::Schedule.every(1.minutes) { Cache.clean_up! }
|
21
|
+
Delayed::Schedule.every(5.minutes) { Mailer.send_status }
|
22
|
+
Delayed::Schedule.every(3.hours) { Database.reimport }
|
23
|
+
|
24
|
+
Delayed::Schedule.worker_select = -> (worker) do
|
25
|
+
worker.queues == [] || worker.queues == ['default']
|
26
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Delayed
|
2
|
+
class Schedule < Plugin
|
3
|
+
callbacks do |lifecycle|
|
4
|
+
lifecycle.before(:loop) do |worker, *_args|
|
5
|
+
Delayed::Schedule.run_tasks if Delayed::Schedule.run?(worker)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.run_tasks
|
10
|
+
@schedule_tasks ||= []
|
11
|
+
@schedule_tasks.select(&:run_necessary?).each do |task|
|
12
|
+
task.perform
|
13
|
+
rescue StandardError => e
|
14
|
+
Rails.logger.error e.message
|
15
|
+
Rails.logger.error e.backtrace.join("\n")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.every(time_range, &block)
|
20
|
+
@schedule_tasks ||= []
|
21
|
+
@schedule_tasks.push(ScheduleTask.new(time_range, block))
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.worker_select=(proc)
|
25
|
+
@worker_select = proc
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.run?(worker)
|
29
|
+
!@worker_select.respond_to?(:call) || @worker_select.call(worker)
|
30
|
+
end
|
31
|
+
|
32
|
+
ScheduleTask = Struct.new(:time_range, :block, :last_run) do
|
33
|
+
def run_necessary?
|
34
|
+
self.last_run ||= Time.now.in_time_zone
|
35
|
+
last_run.nil? || (last_run + time_range) < Time.now.in_time_zone
|
36
|
+
end
|
37
|
+
|
38
|
+
def perform
|
39
|
+
self.last_run = Time.now.in_time_zone
|
40
|
+
block.call
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: delayed_job_schedule
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Georg Limbach
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-02-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: delayed_job
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A plugin for delayed_job to schedule simple tasks. It does not need a
|
42
|
+
seperate worker and reduce the memory usage.
|
43
|
+
email:
|
44
|
+
- georg.limbach@lichtbit.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- MIT-LICENSE
|
50
|
+
- README.rdoc
|
51
|
+
- lib/delayed/schedule.rb
|
52
|
+
- lib/delayed_job_schedule.rb
|
53
|
+
- lib/delayed_job_schedule/engine.rb
|
54
|
+
- lib/delayed_job_schedule/version.rb
|
55
|
+
homepage: https://lichtbit.com
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubygems_version: 3.0.8
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: A plugin for delayed_job to schedule simple tasks.
|
78
|
+
test_files: []
|