qpush 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.byebug_history +43 -0
  3. data/README.md +4 -4
  4. data/bin/console +1 -0
  5. data/jobs/fail_job.rb +1 -1
  6. data/jobs/test_job.rb +1 -1
  7. data/lib/qpush.rb +2 -2
  8. data/lib/qpush/base.rb +7 -5
  9. data/lib/qpush/base/config.rb +41 -0
  10. data/lib/qpush/{job.rb → base/job.rb} +4 -23
  11. data/lib/qpush/base/redis.rb +13 -0
  12. data/lib/qpush/client.rb +7 -0
  13. data/lib/qpush/client/config.rb +13 -0
  14. data/lib/qpush/client/job.rb +12 -0
  15. data/lib/qpush/client/redis.rb +16 -0
  16. data/lib/qpush/jobs/queue_delayed.rb +0 -2
  17. data/lib/qpush/server.rb +10 -7
  18. data/lib/qpush/server/apis.rb +10 -0
  19. data/lib/qpush/server/apis/delay.rb +5 -3
  20. data/lib/qpush/server/apis/execute.rb +0 -4
  21. data/lib/qpush/server/apis/fail.rb +2 -2
  22. data/lib/qpush/server/apis/history.rb +3 -3
  23. data/lib/qpush/server/apis/morgue.rb +3 -7
  24. data/lib/qpush/server/apis/perform.rb +3 -7
  25. data/lib/qpush/server/apis/queue.rb +3 -7
  26. data/lib/qpush/server/apis/setup.rb +1 -5
  27. data/lib/qpush/server/apis/success.rb +3 -7
  28. data/lib/qpush/server/config.rb +49 -0
  29. data/lib/qpush/server/database.rb +1 -1
  30. data/lib/qpush/server/delay.rb +4 -4
  31. data/lib/qpush/server/heartbeat.rb +3 -3
  32. data/lib/qpush/server/jobs.rb +12 -1
  33. data/lib/qpush/server/launcher.rb +3 -3
  34. data/lib/qpush/server/loader.rb +7 -7
  35. data/lib/qpush/server/manager.rb +21 -11
  36. data/lib/qpush/server/perform.rb +1 -2
  37. data/lib/qpush/server/queue.rb +1 -1
  38. data/lib/qpush/server/redis.rb +48 -0
  39. data/lib/qpush/server/worker.rb +57 -23
  40. data/lib/qpush/version.rb +1 -1
  41. data/lib/qpush/web/apis/create.rb +16 -0
  42. data/lib/qpush/web/apis/crons.rb +1 -1
  43. data/lib/qpush/web/apis/heart.rb +1 -1
  44. data/lib/qpush/web/apis/history.rb +1 -1
  45. data/lib/qpush/web/apis/jobs.rb +1 -1
  46. data/lib/qpush/web/apis/morgue.rb +1 -1
  47. data/lib/qpush/web/apis/queue_delayed.rb +1 -1
  48. data/lib/qpush/web/apis/retries.rb +1 -1
  49. data/lib/qpush/web/apis/stats.rb +2 -2
  50. data/lib/qpush/web/config.rb +13 -0
  51. data/lib/qpush/web/get.rb +0 -8
  52. data/lib/qpush/web/post.rb +7 -3
  53. data/lib/qpush/web/public/app/shared/navbar/assets/logo.png +0 -0
  54. data/lib/qpush/web/public/assets/data.json +6 -0
  55. data/lib/qpush/web/public/assets/svg/more.svg +7 -0
  56. data/lib/qpush/web/public/css/main.css +1 -0
  57. data/lib/qpush/web/public/fonts/icons.eot +0 -0
  58. data/lib/qpush/web/public/fonts/icons.otf +0 -0
  59. data/lib/qpush/web/public/fonts/icons.svg +685 -0
  60. data/lib/qpush/web/public/fonts/icons.ttf +0 -0
  61. data/lib/qpush/web/public/fonts/icons.woff +0 -0
  62. data/lib/qpush/web/public/fonts/icons.woff2 +0 -0
  63. data/lib/qpush/web/public/index.html +40 -0
  64. data/lib/qpush/web/public/js/app.js +52 -0
  65. data/lib/qpush/web/public/js/shims.js +15 -0
  66. data/lib/qpush/web/public/tsconfig.json +20 -0
  67. data/lib/qpush/web/redis.rb +16 -0
  68. data/lib/qpush/web/server.rb +9 -5
  69. data/qpush.gemspec +1 -0
  70. metadata +42 -5
  71. data/lib/qpush/config.rb +0 -63
  72. data/lib/qpush/redis.rb +0 -53
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c81c28b25016af05e8ab1560015b659c073fb19a
4
- data.tar.gz: 8e08d686417972044dc952001bd521bdf3a1b700
3
+ metadata.gz: 30fcd80a97393fd4b5d20192e0f90b6b44865eb8
4
+ data.tar.gz: fd5f9ac7220513fb70bd722725e5c7e72fa2ceb3
5
5
  SHA512:
6
- metadata.gz: 90b802ddd706fd24e326e15b1fa4ca4a9a7578dcd87c10512fea84e148b8506b8a34f17b30be996ce9c122dfe4ed95b1ec785a54c5e4e6d5194c49b853f262b1
7
- data.tar.gz: 69302a4491443410a50827ea88b50a3070917c6c108d515eb9ebd3afa2702d33f2f3f549ca9ee688f337c2f862db814ba1c09d7d0de9f36ab5423353b4a88a6b
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 the same manner as above.
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
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
+ require 'qpush/client'
4
5
  require 'qpush/server'
5
6
  require 'qpush/web'
6
7
 
data/jobs/fail_job.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class FailJob
2
- include QPush::Job
2
+ include QPush::Server::JobRegister
3
3
 
4
4
  def initialize(options)
5
5
  @option = options
data/jobs/test_job.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class TestJob
2
- include QPush::Job
2
+ include QPush::Server::JobRegister
3
3
 
4
4
  def call
5
5
  puts 'Hello from TestJob'
data/lib/qpush.rb CHANGED
@@ -1,2 +1,2 @@
1
- # Base
2
- require 'qpush/base'
1
+ # QPush Client Base
2
+ require 'qpush/client'
data/lib/qpush/base.rb CHANGED
@@ -1,10 +1,12 @@
1
- # Base
2
- # require 'byebug'
1
+ # External
2
+ require 'byebug'
3
3
  require 'securerandom'
4
4
  require 'json'
5
5
  require 'redis'
6
6
  require 'connection_pool'
7
- require 'qpush/config'
8
- require 'qpush/job'
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::ClientWrapper.new(options)
4
+ job = Client::Job.new(options)
5
5
  job.queue
6
6
  end
7
7
  end
8
8
 
9
- module Job
10
- class << self
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: QPush.config.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
@@ -0,0 +1,13 @@
1
+ module QPush
2
+ module Base
3
+ KEY = 'qpush:v1'.freeze
4
+
5
+ class RedisPool
6
+ def self.create(pool, url)
7
+ ::ConnectionPool.new(size: pool) do
8
+ ::Redis.new(url: url)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ # QPush Base
2
+ require 'qpush/base'
3
+
4
+ # Qpush Client Base
5
+ require 'qpush/client/config'
6
+ require 'qpush/client/job'
7
+ require 'qpush/client/redis'
@@ -0,0 +1,13 @@
1
+ module QPush
2
+ module Client
3
+ include QPush::Base::ConfigHelper
4
+
5
+ class << self
6
+ def config
7
+ @config ||= Config.new
8
+ end
9
+ end
10
+
11
+ class Config < QPush::Base::Config; end
12
+ end
13
+ end
@@ -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
@@ -1,8 +1,6 @@
1
1
  module QPush
2
2
  module Jobs
3
3
  class QueueDelayed
4
- include QPush::Job
5
-
6
4
  attr_accessor :id, :score
7
5
 
8
6
  def initialize(options)
data/lib/qpush/server.rb CHANGED
@@ -1,13 +1,15 @@
1
- # Base
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'
@@ -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
- QPush.redis.with do |conn|
19
- conn.hincrby(QPush.keys.stats, @stat, 1)
20
- conn.zadd(QPush.keys.delay, @time, @job.to_json)
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
 
@@ -2,10 +2,6 @@ module QPush
2
2
  module Server
3
3
  module Apis
4
4
  class Execute < Base
5
- def initialize(job)
6
- @job = job
7
- end
8
-
9
5
  def call
10
6
  measure_run_time { job_object.call }
11
7
  Success.call(@job)
@@ -23,11 +23,11 @@ module QPush
23
23
  end
24
24
 
25
25
  def stat_increment
26
- QPush.redis.with { |c| c.hincrby(QPush.keys.stats, 'failed', 1) }
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
- QPush.redis.with do |c|
21
- c.lpush(QPush.keys.history, to_json)
22
- c.ltrim(QPush.keys.history, 0, 10)
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