Slide 82
Slide 82 text
defmodule
Worker
do
use
GenServer
def
run(pid,
job)
do
:gen_server.cast(pid,
{:run,
job})
end
def
handle_cast({:run,
job},
client)
do
#
Computed
result
from
Elixir
worker
args
=
[process_stats(job[“args"]
|>
Enum.first)]
job
=
JSON.decode!(job)
new_job
=
HashDict.new
|>
HashDict.put(:queue,
"queue:default")
#
Use
the
Rails
Sidekiq
queue
|>
HashDict.put(:jid,
job["jid"])
|>
HashDict.put(:class,
"HardWorker")
#
Matches
Rails
Worker
|>
HashDict.put(:args,
args)
|>
HashDict.put(:enqueued_at,
job["enqueued_at"])
|>
JSON.encode!
client
|>
Exredis.query(["LPUSH",
queue,
new_job])
{:noreply,
client}
end
end
This is roughly how the worker looks like.
!
Again, the implementation is not important.
!
The important thing is to see what the worker does to the JSON hash. Let’s take a closer look.