-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify the internal API, removing JobWrapper and InlineScheduler (#21)
- Loading branch information
1 parent
1603a09
commit 8c03271
Showing
19 changed files
with
218 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
--color | ||
--order random | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,36 @@ | ||
module GoodJob | ||
class Adapter | ||
def initialize(options = {}) | ||
@options = options | ||
@scheduler = InlineScheduler.new if inline? | ||
def initialize(inline: false) | ||
@inline = inline | ||
end | ||
|
||
def enqueue(job) | ||
enqueue_at(job, nil) | ||
def enqueue(active_job) | ||
enqueue_at(active_job, nil) | ||
end | ||
|
||
def enqueue_at(job, timestamp) | ||
params = { | ||
queue_name: job.queue_name, | ||
priority: job.priority, | ||
serialized_params: job.serialize, | ||
} | ||
params[:scheduled_at] = Time.at(timestamp) if timestamp | ||
def enqueue_at(active_job, timestamp) | ||
good_job = GoodJob::Job.enqueue( | ||
active_job, | ||
scheduled_at: timestamp ? Time.at(timestamp) : nil, | ||
create_with_advisory_lock: inline? | ||
) | ||
|
||
good_job = GoodJob::Job.create(params) | ||
job.provider_job_id = good_job.id | ||
|
||
GoodJob.tag_logger do | ||
ActiveSupport::Notifications.instrument("create.good_job", { good_job: good_job, job: job }) | ||
@scheduler.enqueue(good_job) if inline? | ||
if inline? | ||
good_job.perform | ||
good_job.advisory_unlock | ||
end | ||
|
||
good_job | ||
end | ||
|
||
def shutdown(wait: true) | ||
@scheduler&.shutdown(wait: wait) | ||
def shutdown(wait: true) # rubocop:disable Lint/UnusedMethodArgument | ||
nil | ||
end | ||
|
||
private | ||
|
||
def inline? | ||
@options.fetch(:inline, false) | ||
@inline | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,39 @@ | ||
module GoodJob | ||
class Job < ActiveRecord::Base | ||
include Lockable | ||
|
||
self.table_name = 'good_jobs' | ||
|
||
def self.enqueue(active_job, scheduled_at: nil, create_with_advisory_lock: false) | ||
good_job = nil | ||
ActiveSupport::Notifications.instrument("enqueue_job.good_job", { active_job: active_job, scheduled_at: scheduled_at, create_with_advisory_lock: create_with_advisory_lock }) do |instrument_payload| | ||
good_job = GoodJob::Job.new( | ||
queue_name: active_job.queue_name, | ||
priority: active_job.priority, | ||
serialized_params: active_job.serialize, | ||
scheduled_at: scheduled_at, | ||
create_with_advisory_lock: create_with_advisory_lock | ||
) | ||
|
||
instrument_payload[:good_job] = good_job | ||
|
||
good_job.save! | ||
active_job.provider_job_id = good_job.id | ||
end | ||
|
||
good_job | ||
end | ||
|
||
def perform | ||
ActiveSupport::Notifications.instrument("before_perform_job.good_job", { good_job: self }) | ||
ActiveSupport::Notifications.instrument("perform_job.good_job", { good_job: self }) do | ||
params = serialized_params.merge( | ||
"provider_job_id" => id | ||
) | ||
ActiveJob::Base.execute(params) | ||
|
||
destroy! | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.