@@ -9,6 +9,7 @@ The background task system consists of:
99- ** Job Queue** : Database-backed queue for persistent job storage
1010- ** Worker Pool** : Configurable number of workers processing jobs concurrently
1111- ** Job Registry** : Type-safe job registration and resolution
12+ - ** Console Commands** : Easy job generation and management via CLI
1213- ** Retry Logic** : Automatic retry with exponential backoff
1314- ** Job States** : Track job lifecycle from pending to completion
1415
@@ -27,6 +28,60 @@ type Job interface {
2728
2829## Creating Jobs
2930
31+ ### Generating Jobs with Console Commands
32+
33+ Use the console command system to quickly generate new background jobs:
34+
35+ ``` bash
36+ # Generate a new job
37+ go run main.go console make:job EmailJob
38+
39+ # Generate job with specific name
40+ go run main.go console make:job ProcessPaymentJob
41+
42+ # Generate multiple jobs
43+ go run main.go console make:job ImageProcessorJob
44+ go run main.go console make:job NotificationJob
45+
46+ # List all available make commands
47+ go run main.go console list | grep " make:"
48+ ```
49+
50+ ** Generated job example:**
51+ ``` go
52+ // pkg/queue/jobs/email_job.go
53+ package jobs
54+
55+ import (
56+ " encoding/json"
57+ " time"
58+ " github.com/sheenazien8/goplate/pkg/queue"
59+ )
60+
61+ type EmailJob struct {}
62+
63+ func (j EmailJob ) Type () string {
64+ return " email_job"
65+ }
66+
67+ func (j EmailJob ) Handle (payload json .RawMessage ) error {
68+ // Add your job logic here
69+ return nil
70+ }
71+
72+ func (j EmailJob ) MaxAttempts () int {
73+ return 3
74+ }
75+
76+ func (j EmailJob ) RetryAfter () time .Duration {
77+ return 30 * time.Second
78+ }
79+
80+ func init () {
81+ queue.RegisterJob (EmailJob{})
82+ }
83+ ```
84+
3085### Basic Job Example
3186
3287``` go
@@ -79,6 +134,9 @@ func init() {
79134}
80135```
81136
137+ ** Note** : When you generate a job using ` go run main.go console make:job ` , the job is automatically registered via the ` init() ` function.
138+ ```
139+
82140### Advanced Job Example
83141
84142```go
@@ -151,6 +209,32 @@ func init() {
151209}
152210```
153211
212+ ### Custom Job Development Workflow
213+
214+ 1 . ** Generate the job structure** :
215+ ``` bash
216+ go run main.go console make:job ImageProcessorJob
217+ ```
218+
219+ 2 . ** Implement the job logic** in the generated file:
220+ ``` go
221+ func (j ImageProcessorJob ) Handle (payload json.RawMessage) error {
222+ // Your custom business logic here
223+ return nil
224+ }
225+ ```
226+
227+ 3 . ** Configure retry behavior** :
228+ ``` go
229+ func (j ImageProcessorJob ) MaxAttempts () int {
230+ return 5 // Customize based on your needs
231+ }
232+
233+ func (j ImageProcessorJob ) RetryAfter () time.Duration {
234+ return 1 * time.Minute // Customize retry delay
235+ }
236+ ```
237+
154238## Dispatching Jobs
155239
156240### From Controllers
@@ -330,6 +414,12 @@ func TestJobDispatchAndProcessing(t *testing.T) {
330414
331415## Best Practices
332416
417+ ### Job Development with Console Commands
418+
419+ 1 . ** Use code generation** - Always start with ` go run main.go console make:job ` for consistency
420+ 2 . ** Follow naming conventions** - Use descriptive job names like ` ProcessPaymentJob ` , ` SendEmailJob `
421+ 3 . ** One job per file** - Each job should have its own file in ` pkg/queue/jobs/ `
422+
333423### Job Design
334424
3354251 . ** Keep jobs idempotent** - Jobs should be safe to run multiple times
@@ -353,9 +443,29 @@ func TestJobDispatchAndProcessing(t *testing.T) {
353443
354444---
355445
446+ ## Development Workflow Summary
447+
448+ 1 . ** Generate job** : ` go run main.go console make:job YourJobName `
449+ 2 . ** Implement logic** : Add your business logic to the ` Handle() ` method
450+ 3 . ** Configure retries** : Set appropriate ` MaxAttempts() ` and ` RetryAfter() ` values
451+ 4 . ** Test thoroughly** : Write unit tests for your job logic
452+ 5 . ** Deploy and monitor** : Use logging to track job performance
453+
454+ ## Console Commands Reference
455+
456+ ``` bash
457+ # Job Development
458+ go run main.go console make:job < JobName> # Generate new background job
459+ go run main.go console list # List all available commands
460+
461+ # Related Commands
462+ go run main.go console make:cron < CronName> # Generate CRON job
463+ go run main.go console db:seed # Run database seeders
464+ ```
465+
356466## Next Steps
357467
358- - ** [ Task Scheduler ] ( /task-scheduler ) ** - Learn about CRON-based scheduling
359- - ** [ Logging ] ( /logging ) ** - Implement proper job logging
360- - ** [ Performance ] ( /performance ) ** - Optimize job processing
468+ - ** [ Console Commands ] ( /console-commands ) ** - Master the command-line tools
469+ - ** [ Task Scheduler ] ( /task-scheduler ) ** - Learn about CRON-based scheduling
470+ - ** [ Database ] ( /database ) ** - Understand job storage and models
361471- ** [ Examples] ( /examples/jobs ) ** - See complete job examples
0 commit comments