qpush 0.1.2 → 0.1.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 +4 -4
- data/.byebug_history +74 -0
- data/bin/qpush-server +0 -1
- data/bin/qpush-web +7 -1
- data/jobs/fail_job.rb +11 -0
- data/jobs/test_job.rb +2 -0
- data/lib/qpush/config.rb +0 -20
- data/lib/qpush/job.rb +11 -7
- data/lib/qpush/jobs/queue_delayed.rb +17 -0
- data/lib/qpush/redis.rb +36 -0
- data/lib/qpush/server.rb +20 -2
- data/lib/qpush/server/apis.rb +46 -0
- data/lib/qpush/server/apis/delay.rb +37 -0
- data/lib/qpush/server/apis/execute.rb +32 -0
- data/lib/qpush/server/apis/fail.rb +39 -0
- data/lib/qpush/server/apis/history.rb +36 -0
- data/lib/qpush/server/apis/morgue.rb +24 -0
- data/lib/qpush/server/apis/perform.rb +24 -0
- data/lib/qpush/server/apis/queue.rb +24 -0
- data/lib/qpush/server/apis/setup.rb +27 -0
- data/lib/qpush/server/apis/success.rb +39 -0
- data/lib/qpush/server/delay.rb +5 -5
- data/lib/qpush/server/errors.rb +1 -16
- data/lib/qpush/server/heartbeat.rb +28 -0
- data/lib/qpush/server/jobs.rb +10 -55
- data/lib/qpush/server/launcher.rb +5 -5
- data/lib/qpush/server/loader.rb +38 -0
- data/lib/qpush/server/perform.rb +2 -2
- data/lib/qpush/server/queue.rb +2 -2
- data/lib/qpush/server/worker.rb +1 -0
- data/lib/qpush/version.rb +1 -1
- data/lib/qpush/web.rb +10 -1
- data/lib/qpush/web/apis/crons.rb +34 -0
- data/lib/qpush/web/apis/heart.rb +12 -0
- data/lib/qpush/web/apis/history.rb +28 -0
- data/lib/qpush/web/apis/jobs.rb +26 -0
- data/lib/qpush/web/apis/morgue.rb +30 -0
- data/lib/qpush/web/apis/queue_delayed.rb +29 -0
- data/lib/qpush/web/apis/queued.rb +0 -0
- data/lib/qpush/web/apis/retries.rb +40 -0
- data/lib/qpush/web/apis/stats.rb +58 -0
- data/lib/qpush/web/get.rb +32 -34
- data/lib/qpush/web/post.rb +8 -0
- data/lib/qpush/web/server.rb +34 -5
- data/qpush.gemspec +1 -0
- metadata +40 -3
- data/lib/qpush/server/execute.rb +0 -100
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c81c28b25016af05e8ab1560015b659c073fb19a
|
4
|
+
data.tar.gz: 8e08d686417972044dc952001bd521bdf3a1b700
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90b802ddd706fd24e326e15b1fa4ca4a9a7578dcd87c10512fea84e148b8506b8a34f17b30be996ce9c122dfe4ed95b1ec785a54c5e4e6d5194c49b853f262b1
|
7
|
+
data.tar.gz: 69302a4491443410a50827ea88b50a3070917c6c108d515eb9ebd3afa2702d33f2f3f549ca9ee688f337c2f862db814ba1c09d7d0de9f36ab5423353b4a88a6b
|
data/.byebug_history
CHANGED
@@ -1,3 +1,77 @@
|
|
1
|
+
c
|
2
|
+
request.path_info
|
3
|
+
c
|
4
|
+
hash
|
5
|
+
c
|
6
|
+
@jobs.compact[@start, @count]
|
7
|
+
@jobs.compact
|
8
|
+
@jobs.compact!
|
9
|
+
@count
|
10
|
+
@start
|
11
|
+
@jobs
|
12
|
+
c
|
13
|
+
@count
|
14
|
+
@start
|
15
|
+
@jobs
|
16
|
+
c
|
17
|
+
Delay.call(@job, :delay)
|
18
|
+
c
|
19
|
+
Delay.call(@job)
|
20
|
+
c
|
21
|
+
@stats.each_key { |key| puts key }
|
22
|
+
@stats.each_key { |key| @stats[key].to_i }
|
23
|
+
@stats
|
24
|
+
c
|
25
|
+
@stats
|
26
|
+
c
|
27
|
+
quit
|
28
|
+
Perform.call(@job)
|
29
|
+
c
|
30
|
+
Perform.call(@job)
|
31
|
+
c
|
32
|
+
@job
|
33
|
+
invalid_job && return unless @job.valid?
|
34
|
+
c
|
35
|
+
job
|
36
|
+
c
|
37
|
+
@fails = @fails.compact[@start, @count]
|
38
|
+
@fails
|
39
|
+
@Fails
|
40
|
+
@fails.compact!
|
41
|
+
@fails.compact![@start..@count]
|
42
|
+
@fails.compact![@start, @count]
|
43
|
+
@fails.any?
|
44
|
+
@count
|
45
|
+
@start
|
46
|
+
@fails
|
47
|
+
c
|
48
|
+
@fails
|
49
|
+
c
|
50
|
+
@fails
|
51
|
+
c
|
52
|
+
percent
|
53
|
+
quit
|
54
|
+
y
|
55
|
+
q
|
56
|
+
(100.00 - ((stats[:failed].to_f / stats[:performed].to_f) * 100.00)).round(2)
|
57
|
+
100.00 - ((stats[:failed].to_f / stats[:performed].to_f) * 100.00)
|
58
|
+
stats[:failed].to_f / stats[:performed].to_f
|
59
|
+
stats[:failed].to_f
|
60
|
+
stats[:failed].to_i / stats[:performed].to_i
|
61
|
+
(stats[:failed] / stats[:performed])
|
62
|
+
stats[:performed]
|
63
|
+
stats[:failed]
|
64
|
+
percent
|
65
|
+
c
|
66
|
+
conn.lrange("#{QPush.config.perform_namespace}:last_10", 0, 10)
|
67
|
+
c
|
68
|
+
json
|
69
|
+
c
|
70
|
+
conn.get("#{namespace}:#{s}")
|
71
|
+
stats
|
72
|
+
c
|
73
|
+
nil.to_i
|
74
|
+
stats
|
1
75
|
quit
|
2
76
|
Dir[Dir.pwd + "/lib/qpush/jobs/*.rb"]
|
3
77
|
Dir[Dir.pwd + "/lib/jobs/*.rb"]
|
data/bin/qpush-server
CHANGED
data/bin/qpush-web
CHANGED
data/jobs/fail_job.rb
ADDED
data/jobs/test_job.rb
CHANGED
data/lib/qpush/config.rb
CHANGED
@@ -59,25 +59,5 @@ module QPush
|
|
59
59
|
url: redis_url
|
60
60
|
}
|
61
61
|
end
|
62
|
-
|
63
|
-
def delay_namespace
|
64
|
-
@delay_namespace ||= "qpush:v1:#{@namespace}:delay"
|
65
|
-
end
|
66
|
-
|
67
|
-
def queue_namespace
|
68
|
-
@queue_namespace ||= "qpush:v1:#{@namespace}:queue"
|
69
|
-
end
|
70
|
-
|
71
|
-
def perform_namespace
|
72
|
-
@perform_namespace ||= "qpush:v1:#{@namespace}:perform"
|
73
|
-
end
|
74
|
-
|
75
|
-
def stats_namespace
|
76
|
-
@stats_namespace ||= "qpush:v1:#{@namespace}:stats"
|
77
|
-
end
|
78
|
-
|
79
|
-
def perform_lists
|
80
|
-
(1..priorities).collect { |num| "#{perform_namespace}:#{num}" }
|
81
|
-
end
|
82
62
|
end
|
83
63
|
end
|
data/lib/qpush/job.rb
CHANGED
@@ -9,13 +9,11 @@ module QPush
|
|
9
9
|
module Job
|
10
10
|
class << self
|
11
11
|
def included(base)
|
12
|
-
base
|
12
|
+
_register_job(base)
|
13
13
|
end
|
14
|
-
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
QPush.job(options.merge(klass: name))
|
15
|
+
def _register_job(base)
|
16
|
+
QPush.redis.with { |c| c.sadd(QPush.keys.jobs, base.name) }
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
@@ -23,7 +21,7 @@ module QPush
|
|
23
21
|
attr_accessor :klass, :id, :priority, :created_at, :start_at,
|
24
22
|
:cron, :retry_max, :total_success, :total_fail,
|
25
23
|
:run_time, :namespace
|
26
|
-
attr_reader :args
|
24
|
+
attr_reader :args, :failed
|
27
25
|
|
28
26
|
def initialize(options = {})
|
29
27
|
options = defaults.merge(options)
|
@@ -39,6 +37,10 @@ module QPush
|
|
39
37
|
@args = nil
|
40
38
|
end
|
41
39
|
|
40
|
+
def failed=(failed)
|
41
|
+
@failed = failed == 'true' || failed == true
|
42
|
+
end
|
43
|
+
|
42
44
|
def to_json
|
43
45
|
{ klass: @klass,
|
44
46
|
id: @id,
|
@@ -49,6 +51,7 @@ module QPush
|
|
49
51
|
retry_max: @retry_max,
|
50
52
|
total_fail: @total_fail,
|
51
53
|
total_success: @total_success,
|
54
|
+
failed: @failed,
|
52
55
|
args: @args }.to_json
|
53
56
|
end
|
54
57
|
|
@@ -64,6 +67,7 @@ module QPush
|
|
64
67
|
retry_max: 10,
|
65
68
|
total_fail: 0,
|
66
69
|
total_success: 0,
|
70
|
+
failed: false,
|
67
71
|
namespace: QPush.config.namespace }
|
68
72
|
end
|
69
73
|
end
|
@@ -71,7 +75,7 @@ module QPush
|
|
71
75
|
class ClientWrapper < QPush::Job::Base
|
72
76
|
def queue
|
73
77
|
QPush.redis.with do |conn|
|
74
|
-
conn.
|
78
|
+
conn.hincrby("qpush:v1:#{@namespace}:stats", 'queued', 1)
|
75
79
|
conn.lpush("qpush:v1:#{@namespace}:queue", to_json)
|
76
80
|
end
|
77
81
|
end
|
data/lib/qpush/redis.rb
CHANGED
@@ -5,6 +5,10 @@ module QPush
|
|
5
5
|
def redis
|
6
6
|
@redis_pool ||= RedisPool.create
|
7
7
|
end
|
8
|
+
|
9
|
+
def keys
|
10
|
+
@keys ||= Rediskeys.new
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
class RedisPool
|
@@ -14,4 +18,36 @@ module QPush
|
|
14
18
|
end
|
15
19
|
end
|
16
20
|
end
|
21
|
+
|
22
|
+
class Rediskeys
|
23
|
+
BASE = 'qpush:v1'.freeze
|
24
|
+
KEYS = [:delay,
|
25
|
+
:queue,
|
26
|
+
:perform,
|
27
|
+
:stats,
|
28
|
+
:heart,
|
29
|
+
:jobs,
|
30
|
+
:crons,
|
31
|
+
:history,
|
32
|
+
:morgue]
|
33
|
+
|
34
|
+
attr_reader :delay, :queue, :perform, :stats, :heart, :jobs,
|
35
|
+
:history, :morgue
|
36
|
+
|
37
|
+
def initialize
|
38
|
+
build_keyspaces
|
39
|
+
end
|
40
|
+
|
41
|
+
def perform_lists
|
42
|
+
(1..QPush.config.priorities).collect { |num| "#{perform}:#{num}" }
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def build_keyspaces
|
48
|
+
KEYS.each do |key|
|
49
|
+
instance_variable_set("@#{key}", "#{BASE}:#{QPush.config.namespace}:#{key}")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
17
53
|
end
|
data/lib/qpush/server.rb
CHANGED
@@ -1,18 +1,36 @@
|
|
1
1
|
# Base
|
2
2
|
require 'qpush/base'
|
3
3
|
|
4
|
-
# Server
|
4
|
+
# Server Base
|
5
|
+
require 'byebug'
|
5
6
|
require 'sequel'
|
6
7
|
require 'object_validator'
|
7
8
|
require 'parse-cron'
|
9
|
+
require 'forwardable'
|
10
|
+
require 'qpush/server/apis'
|
8
11
|
require 'qpush/server/database'
|
9
12
|
require 'qpush/server/delay'
|
10
13
|
require 'qpush/server/errors'
|
11
|
-
require 'qpush/server/
|
14
|
+
require 'qpush/server/heartbeat'
|
12
15
|
require 'qpush/server/jobs'
|
13
16
|
require 'qpush/server/launcher'
|
17
|
+
require 'qpush/server/loader'
|
14
18
|
require 'qpush/server/logger'
|
15
19
|
require 'qpush/server/manager'
|
16
20
|
require 'qpush/server/perform'
|
17
21
|
require 'qpush/server/queue'
|
18
22
|
require 'qpush/server/worker'
|
23
|
+
|
24
|
+
# Server Apis
|
25
|
+
require 'qpush/server/apis/delay'
|
26
|
+
require 'qpush/server/apis/execute'
|
27
|
+
require 'qpush/server/apis/fail'
|
28
|
+
require 'qpush/server/apis/history'
|
29
|
+
require 'qpush/server/apis/perform'
|
30
|
+
require 'qpush/server/apis/queue'
|
31
|
+
require 'qpush/server/apis/morgue'
|
32
|
+
require 'qpush/server/apis/setup'
|
33
|
+
require 'qpush/server/apis/success'
|
34
|
+
|
35
|
+
# Base Jobs
|
36
|
+
require 'qpush/jobs/queue_delayed'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module QPush
|
2
|
+
module Server
|
3
|
+
module Apis
|
4
|
+
class Base
|
5
|
+
def self.call(*args)
|
6
|
+
api = new(*args)
|
7
|
+
api.call
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class ApiWrapper
|
13
|
+
def initialize(job)
|
14
|
+
@job = job
|
15
|
+
end
|
16
|
+
|
17
|
+
def queue
|
18
|
+
Apis::Queue.call(@job)
|
19
|
+
end
|
20
|
+
|
21
|
+
def perform
|
22
|
+
Apis::Perform.call(@job)
|
23
|
+
end
|
24
|
+
|
25
|
+
def execute
|
26
|
+
Apis::Execute.call(@job)
|
27
|
+
end
|
28
|
+
|
29
|
+
def delay
|
30
|
+
Apis::Delay.call(@job, :delay)
|
31
|
+
end
|
32
|
+
|
33
|
+
def retry
|
34
|
+
Apis::Delay.call(@job, :retry)
|
35
|
+
end
|
36
|
+
|
37
|
+
def morgue
|
38
|
+
Apis::Morgue.call(@job)
|
39
|
+
end
|
40
|
+
|
41
|
+
def setup
|
42
|
+
Apis::Setup.call(@job)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module QPush
|
2
|
+
module Server
|
3
|
+
module Apis
|
4
|
+
class Delay < Base
|
5
|
+
def initialize(job, type)
|
6
|
+
@job = job
|
7
|
+
@type = type
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
load_type
|
12
|
+
delay_job
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def delay_job
|
18
|
+
QPush.redis.with do |conn|
|
19
|
+
conn.hincrby(QPush.keys.stats, @stat, 1)
|
20
|
+
conn.zadd(QPush.keys.delay, @time, @job.to_json)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def load_type
|
25
|
+
case @type
|
26
|
+
when :delay
|
27
|
+
@stat = 'delayed'
|
28
|
+
@time = @job.delay_until
|
29
|
+
when :retry
|
30
|
+
@stat = 'retries'
|
31
|
+
@time = @job.retry_at
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module QPush
|
2
|
+
module Server
|
3
|
+
module Apis
|
4
|
+
class Execute < Base
|
5
|
+
def initialize(job)
|
6
|
+
@job = job
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
measure_run_time { job_object.call }
|
11
|
+
Success.call(@job)
|
12
|
+
rescue => e
|
13
|
+
Fail.call(@job, e)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def measure_run_time
|
19
|
+
start = Time.now
|
20
|
+
yield
|
21
|
+
finish = Time.now
|
22
|
+
@job.run_time = "#{((finish - start) * 1000.0).round(3)} ms"
|
23
|
+
end
|
24
|
+
|
25
|
+
def job_object
|
26
|
+
klass = Object.const_get(@job.klass)
|
27
|
+
@job.args.empty? ? klass.new : klass.new(@job.args)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module QPush
|
2
|
+
module Server
|
3
|
+
module Apis
|
4
|
+
class Fail < Base
|
5
|
+
def initialize(job, error)
|
6
|
+
@job = job
|
7
|
+
@error = error
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
update_job
|
12
|
+
stat_increment
|
13
|
+
log_error
|
14
|
+
update_history
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def update_job
|
20
|
+
@job.mark_failed
|
21
|
+
@job.retry if @job.retry_job?
|
22
|
+
@job.morgue if @job.dead_job?
|
23
|
+
end
|
24
|
+
|
25
|
+
def stat_increment
|
26
|
+
QPush.redis.with { |c| c.hincrby(QPush.keys.stats, 'failed', 1) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def log_error
|
30
|
+
Server.log.err("Job FAILED | #{@job.klass} | #{@job.id} | #{@error.message}")
|
31
|
+
end
|
32
|
+
|
33
|
+
def update_history
|
34
|
+
History.call(@job, false, @error)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|