Skip to content

Commit 34ab391

Browse files
committed
docs: add background processing example with Mel
1 parent 0575f48 commit 34ab391

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,35 @@ To run processors after promotion, pass `process: true`:
244244
attach 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
250251
attach 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
252276
end
253277
```
254278

0 commit comments

Comments
 (0)