Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow usage of seconds in cron #676

Open
elee1766 opened this issue Sep 2, 2024 · 1 comment
Open

allow usage of seconds in cron #676

elee1766 opened this issue Sep 2, 2024 · 1 comment

Comments

@elee1766
Copy link

elee1766 commented Sep 2, 2024

it would be nice to have support for to run a job every n seconds, so i can do health monitoring every 5 seconds instead of every minute.

the cron libraries you use has support for seconds parsing, both in the frontend https://www.npmjs.com/package/cron-parser and in the backend https://github.com/robfig/cron?tab=readme-ov-file#upgrading-to-v3-june-2019

e.g.

cron.New(cron.WithParser(cron.NewParser(
	cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor,
)))

so maybe it just has to be enabled ?

currently im using cronicle to check every 5 seconds, but i want to switch to dagu.

@yohamta
Copy link
Collaborator

yohamta commented Sep 11, 2024

Hey, thank you for the excellent suggestion! It sounds like a promising idea, and I was thinking about whether it's feasible. Here are the changes that would need to be made:

The scheduler currently ticks every minute. If it runs every second, that might be too frequent, so we'll need to think about how to manage that. Running per second could generate a lot of log and status files on disk, which might lead to inode capacity or performance issues. I believe it's possible, but at the moment, running every second might add too much overhead, and I’m not sure it’s worth it.

My suggestion is to create a loop inside the DAG to achieve a similar effect. For example:

schedule: "* * * * *"
steps:
  - name: health check
     command: bash
     run: |
        #!/bin/bash
        health_check() {
            echo "Performing health check..."
        }
  
        duration=60
        start_time=$(date +%s)
  
        while true; do
            current_time=$(date +%s)
            elapsed=$((current_time - start_time))
  
            if [ $elapsed -ge $duration ]; then
                echo "Health check completed after 1 minute."
                break
            fi
  
            health_check
  
            sleep 1
        done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants