MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sentinelRunPendingScripts

Function sentinelRunPendingScripts

app/redis-6.2.6/src/sentinel.c:843–888  ·  view source on GitHub ↗

Run pending scripts if we are not already at max number of running * scripts. */

Source from the content-addressed store, hash-verified

841/* Run pending scripts if we are not already at max number of running
842 * scripts. */
843void sentinelRunPendingScripts(void) {
844 listNode *ln;
845 listIter li;
846 mstime_t now = mstime();
847
848 /* Find jobs that are not running and run them, from the top to the
849 * tail of the queue, so we run older jobs first. */
850 listRewind(sentinel.scripts_queue,&li);
851 while (sentinel.running_scripts < SENTINEL_SCRIPT_MAX_RUNNING &&
852 (ln = listNext(&li)) != NULL)
853 {
854 sentinelScriptJob *sj = ln->value;
855 pid_t pid;
856
857 /* Skip if already running. */
858 if (sj->flags & SENTINEL_SCRIPT_RUNNING) continue;
859
860 /* Skip if it's a retry, but not enough time has elapsed. */
861 if (sj->start_time && sj->start_time > now) continue;
862
863 sj->flags |= SENTINEL_SCRIPT_RUNNING;
864 sj->start_time = mstime();
865 sj->retry_num++;
866 pid = fork();
867
868 if (pid == -1) {
869 /* Parent (fork error).
870 * We report fork errors as signal 99, in order to unify the
871 * reporting with other kind of errors. */
872 sentinelEvent(LL_WARNING,"-script-error",NULL,
873 "%s %d %d", sj->argv[0], 99, 0);
874 sj->flags &= ~SENTINEL_SCRIPT_RUNNING;
875 sj->pid = 0;
876 } else if (pid == 0) {
877 /* Child */
878 tlsCleanup();
879 execve(sj->argv[0],sj->argv,environ);
880 /* If we are here an error occurred. */
881 _exit(2); /* Don't retry execution. */
882 } else {
883 sentinel.running_scripts++;
884 sj->pid = pid;
885 sentinelEvent(LL_DEBUG,"+script-child",NULL,"%ld",(long)pid);
886 }
887 }
888}
889
890/* How much to delay the execution of a script that we need to retry after
891 * an error?

Callers 1

sentinelTimerFunction · 0.85

Calls 5

listRewindFunction · 0.85
listNextFunction · 0.85
sentinelEventFunction · 0.85
tlsCleanupFunction · 0.85
mstimeFunction · 0.70

Tested by

no test coverage detected