Skip to content

Commit

Permalink
Merge pull request #107 from fractaledmind/context-get-and-set
Browse files Browse the repository at this point in the history
Add #get and #set methods to the Context object to allow for working …
  • Loading branch information
fractaledmind authored Dec 16, 2024
2 parents 02e15f2 + 5d2293f commit ce107af
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 ce107af

Please sign in to comment.