added --legion-cron

This commit is contained in:
Unbit
2013-04-11 09:37:22 +02:00
parent b690148452
commit 65b3fde97c
4 changed files with 51 additions and 3 deletions
+12 -2
View File
@@ -677,7 +677,7 @@ void uwsgi_manage_command_cron(time_t now) {
if (!uwsgi_cron_delta) {
uwsgi_error("localtime()");
uwsgi_error("uwsgi_manage_command_cron()/localtime()");
return;
}
@@ -686,6 +686,16 @@ void uwsgi_manage_command_cron(time_t now) {
while (current_cron) {
#ifdef UWSGI_SSL
// check for legion cron
if (current_cron->legion) {
if (!uwsgi_legion_i_am_the_lord(current_cron->legion)) {
current_cron = current_cron->next;
continue;
}
}
#endif
int run_task = uwsgi_cron_task_needs_execution(uwsgi_cron_delta, current_cron->minute, current_cron->hour, current_cron->day, current_cron->month, current_cron->week);
if (run_task == 1) {
@@ -695,7 +705,7 @@ void uwsgi_manage_command_cron(time_t now) {
//call command
if (current_cron->command) {
if (uwsgi_run_command(current_cron->command, NULL, -1) >= 0) {
uwsgi_log_verbose("[uWSGI-cron] running %s\n", current_cron->command);
uwsgi_log_verbose("[uwsgi-cron] running %s\n", current_cron->command);
}
}
current_cron->last_job = now;
+23
View File
@@ -232,6 +232,29 @@ void uwsgi_opt_add_cron(char *opt, char *value, void *foobar) {
uc->command = value + i;
}
#ifdef UWSGI_SSL
void uwsgi_opt_add_legion_cron(char *opt, char *value, void *foobar) {
char *space = strchr(value, ' ');
if (!space) {
uwsgi_log("invalid legion-cron syntax, must be prefixed with a legion name\n");
exit(1);
}
char *legion = uwsgi_concat2n(value, space-value, "", 0);
uwsgi_opt_add_cron(opt, space+1, foobar);
// now get the last added uwsgi_cron structure
struct uwsgi_cron *uc = uwsgi.crons;
while(uc) {
if (!uc->next) {
uc->legion = legion;
return;
}
}
uwsgi_log("error initializing legion-cron\n");
exit(1);
}
#endif
int uwsgi_signal_add_cron(uint8_t sig, int minute, int hour, int day, int month, int week) {
if (!uwsgi.master_process)
+12 -1
View File
@@ -605,6 +605,10 @@ static struct uwsgi_option uwsgi_base_options[] = {
{"zerg-server", required_argument, 0, "enable the zerg server on the specified UNIX socket", uwsgi_opt_set_str, &uwsgi.zerg_server, UWSGI_OPT_MASTER},
{"cron", required_argument, 0, "add a cron task", uwsgi_opt_add_cron, NULL, UWSGI_OPT_MASTER},
#ifdef UWSGI_SSL
{"legion-cron", required_argument, 0, "add a cron task runnable only when the instance is a lord of the specified legion", uwsgi_opt_add_legion_cron, NULL, UWSGI_OPT_MASTER},
{"cron_cron", required_argument, 0, "add a cron task runnable only when the instance is a lord of the specified legion", uwsgi_opt_add_legion_cron, NULL, UWSGI_OPT_MASTER},
#endif
{"loop", required_argument, 0, "select the uWSGI loop engine", uwsgi_opt_set_str, &uwsgi.loop, 0},
{"loop-list", no_argument, 0, "list enabled loop engines", uwsgi_opt_true, &uwsgi.loop_list, 0},
{"loops-list", no_argument, 0, "list enabled loop engines", uwsgi_opt_true, &uwsgi.loop_list, 0},
@@ -2415,7 +2419,14 @@ unsafe:
if (uwsgi.crons) {
struct uwsgi_cron *ucron = uwsgi.crons;
while (ucron) {
uwsgi_log("command \"%s\" registered as uWSGI-cron task\n", ucron->command);
#ifdef UWSGI_SSL
if (ucron->legion) {
uwsgi_log("[uwsgi-cron] command \"%s\" registered as cron task for legion \"%s\"\n", ucron->command, ucron->legion);
ucron = ucron->next;
continue;
}
#endif
uwsgi_log("[uwsgi-cron] command \"%s\" registered as cron task\n", ucron->command);
ucron = ucron->next;
}
}
+4
View File
@@ -2314,6 +2314,9 @@ struct uwsgi_cron {
uint8_t sig;
char *command;
#ifdef UWSGI_SSL
char *legion;
#endif
struct uwsgi_cron *next;
};
@@ -3182,6 +3185,7 @@ void uwsgi_opt_load_plugin(char *, char *, void *);
void uwsgi_opt_load_dl(char *, char *, void *);
void uwsgi_opt_load(char *, char *, void *);
#ifdef UWSGI_SSL
void uwsgi_opt_add_legion_cron(char *, char *, void *);
void uwsgi_opt_sni(char *, char *, void *);
struct uwsgi_string_list *uwsgi_ssl_add_sni_item(char *, char *, char *, char *, char *);
#endif