Skip to content

Commit

Permalink
Add #get and #set methods to the Context object to allow for working …
Browse files Browse the repository at this point in the history
…with multiple keys at once
  • Loading branch information
fractaledmind committed Dec 16, 2024
1 parent 02e15f2 commit 5d2293f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/acidic_job/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ def initialize(execution)
@execution = execution
end

def set(hash)
AcidicJob.instrument(:set_context, **hash) do
AcidicJob::Value.upsert_all(
hash.map do |key, value|
{ execution_id: @execution.id,
key: key,
value: value }
end,
unique_by: %i[execution_id key]
)
end
end

def get(*keys)
AcidicJob.instrument(:get_context, keys: keys) do
@execution.values.select(:value).where(key: keys).pluck(:value)
end
end

# TODO: deprecate these methods
def []=(key, value)
AcidicJob.instrument(:set_context, key: key, value: value) do
AcidicJob::Value.upsert(
Expand Down

0 comments on commit 5d2293f

Please sign in to comment.