Skip to content

Commit

Permalink
Serialize recurring task's arguments using a custom coder
Browse files Browse the repository at this point in the history
That uses Active Job's arguments serializer/deserializer.
  • Loading branch information
rosa committed Aug 6, 2024
1 parent 7e2b5d1 commit 49ae908
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/solid_queue/recurring_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

module SolidQueue
class RecurringTask < Record
serialize :arguments, coder: JSON
serialize :arguments, coder: Arguments, default: []

class << self
def wrap(args)
args.is_a?(self) ? args : from_configuration(args.first, **args.second)
end

def from_configuration(key, **options)
new(key: key, class_name: options[:class], schedule: options[:schedule], arguments: options[:args] || [])
new(key: key, class_name: options[:class], schedule: options[:schedule], arguments: options[:args])
end
end

Expand Down
13 changes: 13 additions & 0 deletions app/models/solid_queue/recurring_task/arguments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module SolidQueue
class RecurringTask::Arguments
class << self
def load(data)
data.nil? ? [] : ActiveJob::Arguments.deserialize(ActiveSupport::JSON.load(data))
end

def dump(data)
ActiveSupport::JSON.dump(ActiveJob::Arguments.serialize(data)) unless data.nil?
end
end
end
end

0 comments on commit 49ae908

Please sign in to comment.