examples/using-cron-jobs/Readme.md
This example demonstrates how to schedule and run background jobs using the GoFr framework’s built-in Cron Job support.
In this example, we:
counter to run every second.Clone the repository and navigate to this example:
git clone https://github.com/gofr-dev/gofr.git
cd gofr/examples/using-cron-jobs
Run the application:
go run main.go
app.Run() to keep the cron running indefinitely.)app.AddCronJob("* * * * * *", "counter", count)
count function to run every second."* * * * * *" means “every second.”time.Sleep(duration * time.Second)
duration (3 seconds) for demonstration purposes.n.The test (main_test.go):
main() function.Run the test:
go test -v
Expected output:
=== RUN Test_UserPurgeCron
--- PASS: Test_UserPurgeCron (1.10s)
PASS
When running main.go, you should see:
INFO Count: 1
INFO Count: 2
INFO Count: 3