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

adding callback to uwsgi_run_command() #227

Closed
prymitive opened this issue Apr 11, 2013 · 4 comments
Closed

adding callback to uwsgi_run_command() #227

prymitive opened this issue Apr 11, 2013 · 4 comments

Comments

@prymitive
Copy link
Contributor

One of the feature of cluster_cron plugin I'm developing is protecting myself from overlapping cron tasks, example:

I have heavy ruby tasks scheduled every 3 minute, they normally need ~2 minutes to finish, but there might be cases when they start to run longer (for example when DB is under high load), this will cause new cron task to be executed before previous process finishes.

There might be other cases like poor code that will corrupt db data if more than one process is running at a time.

uwsgi_run_command() just starts the command and then master_loop() will log when it is completed as it checks all terminated processes.

I'm not sure how to add such callback, maybe I could make a list with pid, callback pointer and callback arguments (char* would do). Than in master_loop() I would check if pid is on my callback list, if so execute callback function?

Such callback would allow me to unlock the task so next instance can be executed.

@prymitive
Copy link
Contributor Author

we could also add -subprocess-limit option, if enabled we would check in uwsgi_run_command() it the number of currently running subprocesses exceeds defined limit, before executing any subprocess

@unbit
Copy link
Owner

unbit commented May 22, 2013

i think we could a new class of cron/legion-cron

unique-cron = -1 -1 -1 -1 -1 foobar.sh

we store the pid of the process in the uwsgi_cron item, and when the master receive its death we clear it.

Unique crons do not get executed if pid > 0. Obviously if you daemonize in your cron task you are on your own :)

@ghost ghost assigned prymitive May 22, 2013
@prymitive
Copy link
Contributor Author

pid trick sounds good, I'll add such feature

@unbit
Copy link
Owner

unbit commented May 22, 2013

just pay attention (as you need to check for process death in the master) to put the cron iteration in a dedicated function as i do not want to come back to messy master.c :)

You can call that function here: https://github.com/unbit/uwsgi/blob/master/core/master.c#L787

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

No branches or pull requests

2 participants