-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get rid of broadway #149
Get rid of broadway #149
Changes from 11 commits
fba6032
f383313
a20d6d0
02cac14
72c3066
46837d2
33fed68
54ee711
3a651a3
c7fae27
96b8b08
66f7ae1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,13 +59,10 @@ defmodule FaktoryWorker.Job do | |
|
||
## Synchronous job pushing | ||
|
||
By default, jobs are pushed asynchronously to the Faktory server. To ensure a | ||
job has been successfully submitted before continuing, jobs can be pushed | ||
synchronously instead. To do this, pass the `:skip_pipeline` option with the | ||
value of `true` to `perform_async/2`. | ||
|
||
Synchronous pushing is required in certain situations to guarantee ordering, | ||
such as when using the Faktory Enterprise batching feature. | ||
Previous version used Broadway to send jobs and `:skip_pipeline` parameter was used to do it synchronously. | ||
`:skip_pipeline` is not supported anymore. | ||
Since Batch operations is a feature of Faktory Enterprise this library now sends any single job synchronously | ||
and makes HTTP call to faktory server (see `FaktoryWorker.Batch`). | ||
|
||
## Worker Configuration | ||
|
||
|
@@ -88,7 +85,7 @@ defmodule FaktoryWorker.Job do | |
means only values that implement the `Jason.Encoder` protocol are valid when calling the `perform_async/2` function. | ||
""" | ||
|
||
alias FaktoryWorker.{ConnectionManager, Random, Pool, Sandbox, Telemetry} | ||
alias FaktoryWorker.{ConnectionManager, Random, Pool, Telemetry, Sandbox} | ||
|
||
# Look at supporting the following optional fields when pushing a job | ||
# priority | ||
|
@@ -128,36 +125,17 @@ defmodule FaktoryWorker.Job do | |
|
||
@doc false | ||
def perform_async(payload, opts) do | ||
case Keyword.get(opts, :skip_pipeline, false) do | ||
false -> | ||
opts | ||
|> push_pipeline_name() | ||
|> perform_async(payload, opts) | ||
|
||
true -> | ||
opts | ||
|> faktory_name() | ||
|> push(payload) | ||
end | ||
end | ||
|
||
@doc false | ||
def perform_async(_, {:error, _} = error, _), do: error | ||
|
||
def perform_async(pipeline_name, payload, opts) do | ||
if Sandbox.active?() do | ||
Sandbox.enqueue_job( | ||
String.to_existing_atom("Elixir." <> payload.jobtype), | ||
payload.args, | ||
opts | ||
) | ||
{:ok, payload} | ||
else | ||
message = %Broadway.Message{ | ||
acknowledger: {FaktoryWorker.PushPipeline.Acknowledger, :push_message, []}, | ||
data: {pipeline_name, payload} | ||
} | ||
|
||
Broadway.push_messages(pipeline_name, [message]) | ||
opts | ||
|> faktory_name() | ||
|> push(payload) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switching from
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not for this PR, just documenting a thought - but if we can return a Job with the faktory job id here, that would be a great gateway into being able to check on the status of a job. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
+1 for updating documentation as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like we don't need perform_async/3 at all and we can return same result for any call. private function
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be OK to return it as-is. Can you also update There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @superhawk610 we have changed return to {:ok, job}, but I checked our app and I see it always expect :ok. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's change our app to accept There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure that this is mentioned in the upgrade guide as well, as it's a breaking change. |
||
end | ||
end | ||
|
||
|
@@ -170,6 +148,7 @@ defmodule FaktoryWorker.Job do | |
end | ||
|
||
@doc false | ||
def push(_, invalid_payload = {:error, _}), do: invalid_payload | ||
def push(faktory_name, job) do | ||
faktory_name | ||
|> Pool.format_pool_name() | ||
|
@@ -215,12 +194,6 @@ defmodule FaktoryWorker.Job do | |
"The field '#{Atom.to_string(field)}' has an invalid value '#{inspect(value)}'" | ||
end | ||
|
||
defp push_pipeline_name(opts) do | ||
opts | ||
|> faktory_name() | ||
|> FaktoryWorker.PushPipeline.format_pipeline_name() | ||
end | ||
|
||
defp faktory_name(opts) do | ||
Keyword.get(opts, :faktory_name, FaktoryWorker) | ||
end | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to keep the sandbox, it is what we use to simulate the server during testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeremyowensboggs makes sense, I overdid it with simplifications