qpush 0.1.4 → 0.1.6
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 +43 -0
- data/README.md +4 -4
- data/bin/console +1 -0
- data/jobs/fail_job.rb +1 -1
- data/jobs/test_job.rb +1 -1
- data/lib/qpush.rb +2 -2
- data/lib/qpush/base.rb +7 -5
- data/lib/qpush/base/config.rb +41 -0
- data/lib/qpush/{job.rb → base/job.rb} +4 -23
- data/lib/qpush/base/redis.rb +13 -0
- data/lib/qpush/client.rb +7 -0
- data/lib/qpush/client/config.rb +13 -0
- data/lib/qpush/client/job.rb +12 -0
- data/lib/qpush/client/redis.rb +16 -0
- data/lib/qpush/jobs/queue_delayed.rb +0 -2
- data/lib/qpush/server.rb +10 -7
- data/lib/qpush/server/apis.rb +10 -0
- data/lib/qpush/server/apis/delay.rb +5 -3
- data/lib/qpush/server/apis/execute.rb +0 -4
- data/lib/qpush/server/apis/fail.rb +2 -2
- data/lib/qpush/server/apis/history.rb +3 -3
- data/lib/qpush/server/apis/morgue.rb +3 -7
- data/lib/qpush/server/apis/perform.rb +3 -7
- data/lib/qpush/server/apis/queue.rb +3 -7
- data/lib/qpush/server/apis/setup.rb +1 -5
- data/lib/qpush/server/apis/success.rb +3 -7
- data/lib/qpush/server/config.rb +49 -0
- data/lib/qpush/server/database.rb +1 -1
- data/lib/qpush/server/delay.rb +4 -4
- data/lib/qpush/server/heartbeat.rb +3 -3
- data/lib/qpush/server/jobs.rb +12 -1
- data/lib/qpush/server/launcher.rb +3 -3
- data/lib/qpush/server/loader.rb +7 -7
- data/lib/qpush/server/manager.rb +21 -11
- data/lib/qpush/server/perform.rb +1 -2
- data/lib/qpush/server/queue.rb +1 -1
- data/lib/qpush/server/redis.rb +48 -0
- data/lib/qpush/server/worker.rb +57 -23
- data/lib/qpush/version.rb +1 -1
- data/lib/qpush/web/apis/create.rb +16 -0
- data/lib/qpush/web/apis/crons.rb +1 -1
- data/lib/qpush/web/apis/heart.rb +1 -1
- data/lib/qpush/web/apis/history.rb +1 -1
- data/lib/qpush/web/apis/jobs.rb +1 -1
- data/lib/qpush/web/apis/morgue.rb +1 -1
- data/lib/qpush/web/apis/queue_delayed.rb +1 -1
- data/lib/qpush/web/apis/retries.rb +1 -1
- data/lib/qpush/web/apis/stats.rb +2 -2
- data/lib/qpush/web/config.rb +13 -0
- data/lib/qpush/web/get.rb +0 -8
- data/lib/qpush/web/post.rb +7 -3
- data/lib/qpush/web/public/app/shared/navbar/assets/logo.png +0 -0
- data/lib/qpush/web/public/assets/data.json +6 -0
- data/lib/qpush/web/public/assets/svg/more.svg +7 -0
- data/lib/qpush/web/public/css/main.css +1 -0
- data/lib/qpush/web/public/fonts/icons.eot +0 -0
- data/lib/qpush/web/public/fonts/icons.otf +0 -0
- data/lib/qpush/web/public/fonts/icons.svg +685 -0
- data/lib/qpush/web/public/fonts/icons.ttf +0 -0
- data/lib/qpush/web/public/fonts/icons.woff +0 -0
- data/lib/qpush/web/public/fonts/icons.woff2 +0 -0
- data/lib/qpush/web/public/index.html +40 -0
- data/lib/qpush/web/public/js/app.js +52 -0
- data/lib/qpush/web/public/js/shims.js +15 -0
- data/lib/qpush/web/public/tsconfig.json +20 -0
- data/lib/qpush/web/redis.rb +16 -0
- data/lib/qpush/web/server.rb +9 -5
- data/qpush.gemspec +1 -0
- metadata +42 -5
- data/lib/qpush/config.rb +0 -63
- data/lib/qpush/redis.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30fcd80a97393fd4b5d20192e0f90b6b44865eb8
|
4
|
+
data.tar.gz: fd5f9ac7220513fb70bd722725e5c7e72fa2ceb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3c877c1e9e2412d7529d414f6c3282c560ef40f016ea4b293d54cc3485acd6921c980bf92fd1a4e4f8a07278bbe2406fafa18080c39847956164e8f412863e4
|
7
|
+
data.tar.gz: 9fd65ca2be6e3d24641781a02f04d4c53fba13890430d24286a7383e71a55a78c9ee8ba9bd0111aa5f2a76809cce065d280f0df9577af38303af45941a90b797
|
data/.byebug_history
CHANGED
@@ -1,4 +1,47 @@
|
|
1
1
|
c
|
2
|
+
self.config
|
3
|
+
config
|
4
|
+
Server.config
|
5
|
+
c
|
6
|
+
Server.config
|
7
|
+
c
|
8
|
+
QPush::Server.config
|
9
|
+
c
|
10
|
+
QPush::Server.config
|
11
|
+
c
|
12
|
+
job.perform
|
13
|
+
job = Job.new(JSON.parse(json))
|
14
|
+
json
|
15
|
+
c
|
16
|
+
delays.count
|
17
|
+
delays.any?
|
18
|
+
delays
|
19
|
+
@conn
|
20
|
+
c
|
21
|
+
valid?
|
22
|
+
c
|
23
|
+
configs
|
24
|
+
c
|
25
|
+
configs
|
26
|
+
c
|
27
|
+
valid?
|
28
|
+
config
|
29
|
+
c
|
30
|
+
valid?
|
31
|
+
@configs
|
32
|
+
configs
|
33
|
+
c
|
34
|
+
configs ? true : false
|
35
|
+
configs
|
36
|
+
c
|
37
|
+
valid?
|
38
|
+
quit
|
39
|
+
job.klass
|
40
|
+
job.errors
|
41
|
+
job.valid?
|
42
|
+
c
|
43
|
+
jobs
|
44
|
+
c
|
2
45
|
request.path_info
|
3
46
|
c
|
4
47
|
hash
|
data/README.md
CHANGED
@@ -37,7 +37,7 @@ By providing a path to a configuration file, we can setup QPush with plain old r
|
|
37
37
|
|
38
38
|
```ruby
|
39
39
|
# QPush server configuration
|
40
|
-
QPush.configure do |config|
|
40
|
+
QPush::Server.configure do |config|
|
41
41
|
# Your redis server url and number of connections to provide
|
42
42
|
config.redis_url = ENV['REDIS_URL']
|
43
43
|
config.redis_pool = 10
|
@@ -48,13 +48,13 @@ Once the QPush server is running, it will begin processing any queued jobs based
|
|
48
48
|
|
49
49
|
#### The Client
|
50
50
|
|
51
|
-
Before we can add jobs to our server, we must first ensure our client has the same connection to our Redis server. We can setup our configuration in
|
51
|
+
Before we can add jobs to our server, we must first ensure our client has the same connection to our Redis server. We can setup our configuration in a similar manner as above.
|
52
52
|
|
53
53
|
```ruby
|
54
54
|
require 'qpush'
|
55
55
|
|
56
56
|
# QPush client configuration
|
57
|
-
QPush.configure do |config|
|
57
|
+
QPush::Client.configure do |config|
|
58
58
|
# Your redis server url and number of connections to provide
|
59
59
|
config.redis_url = ENV['REDIS_URL']
|
60
60
|
config.redis_pool = 10
|
@@ -121,7 +121,7 @@ Although QPush is designed to independent in its operation, it still provides ac
|
|
121
121
|
require 'pg'
|
122
122
|
|
123
123
|
# QPush database configuration
|
124
|
-
QPush.configure do |config|
|
124
|
+
QPush::Server.configure do |config|
|
125
125
|
# Redis and additional config omitted
|
126
126
|
# ....
|
127
127
|
# ....
|
data/bin/console
CHANGED
data/jobs/fail_job.rb
CHANGED
data/jobs/test_job.rb
CHANGED
data/lib/qpush.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
# Base
|
2
|
-
require 'qpush/
|
1
|
+
# QPush Client Base
|
2
|
+
require 'qpush/client'
|
data/lib/qpush/base.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# External
|
2
|
+
require 'byebug'
|
3
3
|
require 'securerandom'
|
4
4
|
require 'json'
|
5
5
|
require 'redis'
|
6
6
|
require 'connection_pool'
|
7
|
-
|
8
|
-
|
9
|
-
require 'qpush/redis'
|
7
|
+
|
8
|
+
# QPush Base
|
10
9
|
require 'qpush/version'
|
10
|
+
require 'qpush/base/config'
|
11
|
+
require 'qpush/base/job'
|
12
|
+
require 'qpush/base/redis'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module QPush
|
2
|
+
module Base
|
3
|
+
module ConfigHelper
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def configure
|
10
|
+
reset
|
11
|
+
yield(config)
|
12
|
+
end
|
13
|
+
|
14
|
+
def reset_
|
15
|
+
@config = nil
|
16
|
+
@redis_pool = nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Config
|
22
|
+
DEFAULTS = {
|
23
|
+
redis_url: ENV['REDIS_URL'],
|
24
|
+
redis_pool: 10
|
25
|
+
}.freeze
|
26
|
+
|
27
|
+
attr_accessor :redis_url, :redis_pool
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
DEFAULTS.each { |key, value| send("#{key}=", value) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def redis
|
34
|
+
{
|
35
|
+
size: redis_pool,
|
36
|
+
url: redis_url
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,23 +1,13 @@
|
|
1
1
|
module QPush
|
2
2
|
class << self
|
3
3
|
def job(options)
|
4
|
-
job = Job
|
4
|
+
job = Client::Job.new(options)
|
5
5
|
job.queue
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
module
|
10
|
-
class
|
11
|
-
def included(base)
|
12
|
-
_register_job(base)
|
13
|
-
end
|
14
|
-
|
15
|
-
def _register_job(base)
|
16
|
-
QPush.redis.with { |c| c.sadd(QPush.keys.jobs, base.name) }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class Base
|
9
|
+
module Base
|
10
|
+
class Job
|
21
11
|
attr_accessor :klass, :id, :priority, :created_at, :start_at,
|
22
12
|
:cron, :retry_max, :total_success, :total_fail,
|
23
13
|
:run_time, :namespace
|
@@ -68,16 +58,7 @@ module QPush
|
|
68
58
|
total_fail: 0,
|
69
59
|
total_success: 0,
|
70
60
|
failed: false,
|
71
|
-
namespace:
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
class ClientWrapper < QPush::Job::Base
|
76
|
-
def queue
|
77
|
-
QPush.redis.with do |conn|
|
78
|
-
conn.hincrby("qpush:v1:#{@namespace}:stats", 'queued', 1)
|
79
|
-
conn.lpush("qpush:v1:#{@namespace}:queue", to_json)
|
80
|
-
end
|
61
|
+
namespace: 'default' }
|
81
62
|
end
|
82
63
|
end
|
83
64
|
end
|
data/lib/qpush/client.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module QPush
|
2
|
+
module Client
|
3
|
+
class Job < QPush::Base::Job
|
4
|
+
def queue
|
5
|
+
Client.redis do |conn|
|
6
|
+
conn.hincrby("#{QPush::Base::KEY}:#{@namespace}:stats", 'queued', 1)
|
7
|
+
conn.lpush("#{QPush::Base::KEY}:#{@namespace}:queue", to_json)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module QPush
|
2
|
+
module Client
|
3
|
+
class << self
|
4
|
+
def redis
|
5
|
+
redis_pool.with do |conn|
|
6
|
+
yield conn
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def redis_pool
|
11
|
+
@redis_pool ||= QPush::Base::RedisPool.create(Client.config.redis_pool,
|
12
|
+
Client.config.redis_url)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/qpush/server.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
#
|
2
|
-
require 'qpush/base'
|
3
|
-
|
4
|
-
# Server Base
|
5
|
-
require 'byebug'
|
1
|
+
# External
|
6
2
|
require 'sequel'
|
7
3
|
require 'object_validator'
|
8
4
|
require 'parse-cron'
|
9
5
|
require 'forwardable'
|
6
|
+
|
7
|
+
# QPush Base
|
8
|
+
require 'qpush/base'
|
9
|
+
|
10
|
+
# Qpush Server Base
|
10
11
|
require 'qpush/server/apis'
|
12
|
+
require 'qpush/server/config'
|
11
13
|
require 'qpush/server/database'
|
12
14
|
require 'qpush/server/delay'
|
13
15
|
require 'qpush/server/errors'
|
@@ -19,9 +21,10 @@ require 'qpush/server/logger'
|
|
19
21
|
require 'qpush/server/manager'
|
20
22
|
require 'qpush/server/perform'
|
21
23
|
require 'qpush/server/queue'
|
24
|
+
require 'qpush/server/redis'
|
22
25
|
require 'qpush/server/worker'
|
23
26
|
|
24
|
-
# Server Apis
|
27
|
+
# QPush Server Apis
|
25
28
|
require 'qpush/server/apis/delay'
|
26
29
|
require 'qpush/server/apis/execute'
|
27
30
|
require 'qpush/server/apis/fail'
|
@@ -32,5 +35,5 @@ require 'qpush/server/apis/morgue'
|
|
32
35
|
require 'qpush/server/apis/setup'
|
33
36
|
require 'qpush/server/apis/success'
|
34
37
|
|
35
|
-
# Base Jobs
|
38
|
+
# QPush Base Jobs
|
36
39
|
require 'qpush/jobs/queue_delayed'
|
data/lib/qpush/server/apis.rb
CHANGED
@@ -1,14 +1,24 @@
|
|
1
1
|
module QPush
|
2
2
|
module Server
|
3
3
|
module Apis
|
4
|
+
# A Base class for all API classes.
|
5
|
+
#
|
4
6
|
class Base
|
5
7
|
def self.call(*args)
|
6
8
|
api = new(*args)
|
7
9
|
api.call
|
8
10
|
end
|
11
|
+
|
12
|
+
def initialize(job)
|
13
|
+
@job = job
|
14
|
+
end
|
9
15
|
end
|
10
16
|
end
|
11
17
|
|
18
|
+
# The ApiWrapper provides simple wrapper functions for all the API
|
19
|
+
# classes available for jobs. This provides a single entry point to
|
20
|
+
# the API's for job objects.
|
21
|
+
#
|
12
22
|
class ApiWrapper
|
13
23
|
def initialize(job)
|
14
24
|
@job = job
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module QPush
|
2
2
|
module Server
|
3
3
|
module Apis
|
4
|
+
# The Delay API will take a job and add it to the delay sorted set.
|
5
|
+
#
|
4
6
|
class Delay < Base
|
5
7
|
def initialize(job, type)
|
6
8
|
@job = job
|
@@ -15,9 +17,9 @@ module QPush
|
|
15
17
|
private
|
16
18
|
|
17
19
|
def delay_job
|
18
|
-
|
19
|
-
conn.hincrby(
|
20
|
-
conn.zadd(
|
20
|
+
Server.redis do |conn|
|
21
|
+
conn.hincrby(Server.keys.stats, @stat, 1)
|
22
|
+
conn.zadd(Server.keys.delay, @time, @job.to_json)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
@@ -23,11 +23,11 @@ module QPush
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def stat_increment
|
26
|
-
|
26
|
+
Server.redis { |c| c.hincrby(Server.keys.stats, 'failed', 1) }
|
27
27
|
end
|
28
28
|
|
29
29
|
def log_error
|
30
|
-
Server.log.err("Job FAILED | #{@job.klass} | #{@job.id} | #{@error.message}")
|
30
|
+
Server.log.err("Worker #{Server.worker.id} | Job FAILED | #{@job.klass} | #{@job.id} | #{@error.message}")
|
31
31
|
end
|
32
32
|
|
33
33
|
def update_history
|
@@ -17,9 +17,9 @@ module QPush
|
|
17
17
|
private
|
18
18
|
|
19
19
|
def update_history
|
20
|
-
|
21
|
-
c.lpush(
|
22
|
-
c.ltrim(
|
20
|
+
Server.redis do |c|
|
21
|
+
c.lpush(Server.keys.history, to_json)
|
22
|
+
c.ltrim(Server.keys.history, 0, 10)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|