File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -244,11 +244,35 @@ To run processors after promotion, pass `process: true`:
244244attach avatar, process: true
245245` ` `
246246
247- For background processing, pass a block instead :
247+ For background processing, pass a block instead. For example, using
248+ [Mel](https://github.com/GrottoPress/mel) :
248249
249250` ` ` crystal
250251attach avatar do |record|
251- ProcessAvatarJob.perform_async(record.id)
252+ AvatarProcessingJob.run(record_id: record.id)
253+ end
254+ ` ` `
255+
256+ The background job :
257+
258+ ` ` ` crystal
259+ struct AvatarProcessingJob
260+ include Mel::Job::Now
261+
262+ def initialize(@record_id : Int64)
263+ end
264+
265+ def run
266+ # If the avatar is nilable
267+ user.avatar.try(&.process)
268+
269+ # or if it is not nilable:
270+ user.avatar.process
271+ end
272+
273+ private def user
274+ user = UserQuery.find(record_id)
275+ end
252276end
253277` ` `
254278
You can’t perform that action at this time.
0 commit comments