qpush 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 806a9acd2181b5402712357fa31dbd83bc07043f
4
+ data.tar.gz: 63ac3b505e48c766626f93982577c313944dd6e5
5
+ SHA512:
6
+ metadata.gz: bdfa048b61f185be1f2c4609b38c30ddeb5c21c54f37d1e936a1929b7151619e364dd1a5ccb988c2e76d905b52a4aeec688ce05156ec9dac69d6ea151c87d566
7
+ data.tar.gz: 5d46f619f6c2c13e809ed8907cf1699b39f57036903de319fe71bc9f63e1de62945e13f359314aa9de3f64d03411232dd788fa96a46bcb3a52ae8546da45e290
@@ -0,0 +1,107 @@
1
+ quit
2
+ puts e
3
+ puts s
4
+ c
5
+ puts e
6
+ puts s
7
+ s
8
+ jobs.compact!
9
+ jobs.compact![s, e]
10
+ jobs
11
+ quit
12
+ jobs
13
+ c
14
+ jobs
15
+ quit
16
+ job_hash
17
+ quit
18
+ delayed_jobs
19
+ delay_jobs
20
+ c
21
+ conn.zrange(QPush.config.delay_namespace, 0, -1, with_scores: true)
22
+ delayed_jobs
23
+ quit
24
+ conn.get("#{@namespace}:#{stat}")
25
+ "#{@namespace}:#{stat}"
26
+ c
27
+ name
28
+ c
29
+ self.name
30
+ quit
31
+ job
32
+ delays.each { |job| PerformJob.call(Job.new(job)) }
33
+ cccccccccccc
34
+ elcccccccccccccccccccc
35
+ delaysdelays.each {|job| PerformJob.call(Job.new(job))}
36
+ quit
37
+ Server.connection_pool
38
+ Qued::QPush.redis
39
+ QPush.redis
40
+ c
41
+ QueueJob.new(job).call
42
+ job.valid? && job.queueable?
43
+ job.valid?
44
+ return false unless job.valid? && job.queueable?
45
+ job
46
+ quit
47
+ @start_at < Time.now.to_i && !@cron.empty?
48
+ @start_at > Time.now.to_i && @cron.empty?
49
+ @start_at < Time.now.to_i && @cron.empty?
50
+ QueueJob.new(self).call
51
+ quit
52
+ job.valid?
53
+ job.save
54
+ test
55
+ quit
56
+ job.save
57
+ job
58
+ job = Job.new(options)
59
+ options
60
+ quit
61
+ cron?
62
+ delay?
63
+ queue?
64
+ quit
65
+ c
66
+ job_type.call
67
+ quit
68
+ job_type.call
69
+ quit
70
+ performer
71
+ performer = retrieve_job_type
72
+ quit
73
+ self
74
+ performer.call
75
+ performer
76
+ performer = retrieve_job_type
77
+ performer.call
78
+ performer
79
+ retrieve_job_type
80
+ performer
81
+ c
82
+ quit
83
+ performer.call
84
+ performer
85
+ performer = retrieve_job_type
86
+ valid?
87
+ c
88
+ @job.queue?
89
+ @job.delay?
90
+ @job.cron?
91
+ @job
92
+ job_success
93
+ measure_run_time { @job.run }
94
+ @job.run
95
+ c
96
+ quit
97
+ log_success
98
+ job_success && log_success
99
+ c
100
+ @job.run
101
+ @job = Job.new(JSON.parse(json))
102
+ c
103
+ @job = Job.new(JSON.parse(json))
104
+ json
105
+ quit
106
+ json
107
+ son
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at nsweeting@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in job_que.gemspec
4
+ gemspec
5
+
6
+ gem 'pg'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Nicholas Sweeting
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,154 @@
1
+ # QPush
2
+ [![Code Climate](https://codeclimate.com/github/nsweeting/qpush/badges/gpa.svg)](https://codeclimate.com/github/nsweeting/qpush)
3
+
4
+ Fast and simple job queue microservice for Ruby. **Please consider it under development at the moment.**
5
+
6
+ QPush provides a scalable solution to your background job processing needs. Its Redis-backed, with support for forking and threading - letting it process an enormous amount of jobs in short order.
7
+
8
+ As a microservice, QPush is meant to be independent in its operation and deployment. This means that unlike other job processors such as Sidekiq, DelayedJob, etc - QPush does not hook into a web framework. Jobs must therefore be self-sufficent in their operation. This can often lead to better application designs - but also means QPush will have a minimal memory footprint.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'qpush'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install job_que
25
+
26
+ ## Usage
27
+
28
+ Before starting, ensure you have a functioning Redis server available.
29
+
30
+ #### The Server
31
+
32
+ In order to process queued jobs, we run the QPush server. This is a separate service beyond your web application (Rails, Sinatra, etc). To start the server simply type the following in your console.
33
+
34
+ $ bundle exec qpush-server -c path/to/config.rb
35
+
36
+ By providing a path to a configuration file, we can setup QPush with plain old ruby. At a minimum, we should provide details on our Redis server and connections. There are more configuration options available - all of which can be viewed here (to come).
37
+
38
+ ```ruby
39
+ # QPush server configuration
40
+ QPush.configure do |config|
41
+ # Your redis server url and number of connections to provide
42
+ config.redis_url = ENV['REDIS_URL']
43
+ config.redis_pool = 10
44
+ end
45
+ ```
46
+
47
+ Once the QPush server is running, it will begin processing any queued jobs based on priority.
48
+
49
+ #### The Client
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.
52
+
53
+ ```ruby
54
+ require 'qpush'
55
+
56
+ # QPush client configuration
57
+ QPush.configure do |config|
58
+ # Your redis server url and number of connections to provide
59
+ config.redis_url = ENV['REDIS_URL']
60
+ config.redis_pool = 10
61
+ end
62
+ ```
63
+
64
+ With our client setup, we can now queue jobs on our QPush server. All we have to do is:
65
+
66
+ ```ruby
67
+ QPush.job(klass: 'Example::Job', args: { example: 'Job' })
68
+ ```
69
+
70
+ The job above would be equivalent to running the following command on the server.
71
+
72
+ ```ruby
73
+ Example::Job.new(example: 'Job').call
74
+ ```
75
+
76
+ At a minimum, we must provide the job with a 'klass'. There are many more options that we can provide to the job though - all of which can be viewed here (to come).
77
+
78
+ #### Building Jobs
79
+
80
+ Jobs are simply plain old ruby objects that contain a 'call' method. If you provide a hash for the 'args' of the job, the job will be initialized with them. Below is an example of a simple mailing job utilizing the 'mail' gem.
81
+
82
+ ```ruby
83
+ require 'mail'
84
+
85
+ class MailJob
86
+ def initialize(options = {})
87
+ @mail = Mail.new(options)
88
+ end
89
+
90
+ def call
91
+ @mail.deliver
92
+ end
93
+ end
94
+ ```
95
+
96
+ From our client, we could then queue a mail job with the following:
97
+
98
+ ```ruby
99
+ mail_options = { to: 'person@example.com', from: 'admin@test.com', subject: 'Hello!', body: 'From MailJob' }
100
+ QPush.job(klass: 'MailJob', args: mail_options)
101
+ ```
102
+
103
+ #### Failed Jobs
104
+
105
+ Jobs that raise an error will be sent to the retry queue. As a default, they are set to attempt a maximum of 10 retries. Each failed attempt creates a longer delay for subsequent attempts. The job will permanently fail once the max retries has been hit.
106
+
107
+ #### Cron Jobs
108
+
109
+ QPush supports cron jobs. All you have to do is include a cron expression with your job. For example, the following would perform our job everyday at 4AM UTC.
110
+
111
+ ```ruby
112
+ QPush.job(klass: 'Example::Job', args: { example: 'Job' }, cron: '0 4 * * *')
113
+ ```
114
+
115
+ #### Relational Databases
116
+
117
+ Although QPush is designed to independent in its operation, it still provides access to relational databases via Sequel. You can read more about [how to use Sequel here](https://github.com/jeremyevans/sequel). Suffice to say, its quite easy. We first will need to add the required information to our configuration:
118
+
119
+ ```ruby
120
+ # You must remember to require the gem for whatever database you will be using.
121
+ require 'pg'
122
+
123
+ # QPush database configuration
124
+ QPush.configure do |config|
125
+ # Redis and additional config omitted
126
+ # ....
127
+ # ....
128
+ # Your database server url and number of connections to provide
129
+ config.database_url = ENV['DATABASE_URL']
130
+ config.database_pool = 10
131
+ end
132
+ ```
133
+
134
+ We can then access the database from any job. For example, we could retrieve all of our users with the following:
135
+
136
+ ```ruby
137
+ QPush.db[:users].all
138
+ ```
139
+ It is recommended that you read up on Sequel before use.
140
+
141
+ ## Development
142
+
143
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
144
+
145
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
146
+
147
+ ## Contributing
148
+
149
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/job_que. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
150
+
151
+
152
+ ## License
153
+
154
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require 'qpush/server'
5
+ require 'qpush/web'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'qpush/server'
4
+
5
+ server = QPush::Server::Launcher.new(ARGV)
6
+ server.start
@@ -0,0 +1 @@
1
+ exec( "bundle exec rackup lib/qpush/web/server.ru" )
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,2 @@
1
+ # Base
2
+ require 'qpush/base'
@@ -0,0 +1,12 @@
1
+ # Base
2
+ # require 'byebug'
3
+ require 'securerandom'
4
+ require 'json'
5
+ require 'redis'
6
+ require 'connection_pool'
7
+ require 'qpush/config'
8
+ require 'qpush/job'
9
+ require 'qpush/redis'
10
+ require 'qpush/version'
11
+
12
+ require 'qpush/jobs/test_job'
@@ -0,0 +1,70 @@
1
+ module QPush
2
+ class << self
3
+ def configure
4
+ reset
5
+ yield(config)
6
+ end
7
+
8
+ def config
9
+ @config ||= Config.new
10
+ end
11
+
12
+ def reset
13
+ @config = nil
14
+ @connection_pool = nil
15
+ end
16
+ end
17
+
18
+ class Config
19
+ DEFAULTS = {
20
+ redis_url: ENV['REDIS_URL'],
21
+ database_url: ENV['DATABASE_URL'],
22
+ redis_pool: 10,
23
+ database_pool: 10,
24
+ workers: 2,
25
+ stats_namespace: 'qpush:v1:stats',
26
+ queue_threads: 2,
27
+ queue_namespace: 'qpush:v1:queue',
28
+ perform_threads: 2,
29
+ perform_namespace: 'qpush:v1:perform',
30
+ delay_threads:1,
31
+ delay_namespace: 'qpush:v1:delay',
32
+ priorities: 5
33
+ }.freeze
34
+
35
+ attr_accessor :workers, :queue_threads, :queue_namespace, :delay_threads,
36
+ :delay_namespace, :perform_threads, :perform_namespace,
37
+ :stats_namespace, :redis_url, :redis_pool, :priorities,
38
+ :database_url, :database_pool, :database_adapter
39
+
40
+ def initialize
41
+ DEFAULTS.each { |key, value| send("#{key}=", value) }
42
+ end
43
+
44
+ def worker_options
45
+ {
46
+ perform_threads: perform_threads,
47
+ queue_threads: queue_threads,
48
+ delay_threads: delay_threads
49
+ }
50
+ end
51
+
52
+ def manager_options
53
+ {
54
+ workers: workers,
55
+ options: worker_options
56
+ }
57
+ end
58
+
59
+ def redis
60
+ {
61
+ size: redis_pool,
62
+ url: redis_url
63
+ }
64
+ end
65
+
66
+ def perform_lists
67
+ (1..priorities).collect { |num| "#{perform_namespace}:#{num}" }
68
+ end
69
+ end
70
+ end