MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / sentinelScheduleScriptExecution

Function sentinelScheduleScriptExecution

src/sentinel.cpp:781–825  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

779
780#define SENTINEL_SCRIPT_MAX_ARGS 16
781void sentinelScheduleScriptExecution(char *path, ...) {
782 va_list ap;
783 char *argv[SENTINEL_SCRIPT_MAX_ARGS+1];
784 int argc = 1;
785 sentinelScriptJob *sj;
786
787 va_start(ap, path);
788 while(argc < SENTINEL_SCRIPT_MAX_ARGS) {
789 argv[argc] = va_arg(ap,char*);
790 if (!argv[argc]) break;
791 argv[argc] = sdsnew(argv[argc]); /* Copy the string. */
792 argc++;
793 }
794 va_end(ap);
795 argv[0] = sdsnew(path);
796
797 sj = (sentinelScriptJob*)zmalloc(sizeof(*sj), MALLOC_LOCAL);
798 sj->flags = SENTINEL_SCRIPT_NONE;
799 sj->retry_num = 0;
800 sj->argv = (char**)zmalloc(sizeof(char*)*(argc+1), MALLOC_LOCAL);
801 sj->start_time = 0;
802 sj->pid = 0;
803 memcpy(sj->argv,argv,sizeof(char*)*(argc+1));
804
805 listAddNodeTail(sentinel.scripts_queue,sj);
806
807 /* Remove the oldest non running script if we already hit the limit. */
808 if (listLength(sentinel.scripts_queue) > SENTINEL_SCRIPT_MAX_QUEUE) {
809 listNode *ln;
810 listIter li;
811
812 listRewind(sentinel.scripts_queue,&li);
813 while ((ln = listNext(&li)) != NULL) {
814 sj = (sentinelScriptJob*)ln->value;
815
816 if (sj->flags & SENTINEL_SCRIPT_RUNNING) continue;
817 /* The first node is the oldest as we add on tail. */
818 listDelNode(sentinel.scripts_queue,ln);
819 sentinelReleaseScriptJob(sj);
820 break;
821 }
822 serverAssert(listLength(sentinel.scripts_queue) <=
823 SENTINEL_SCRIPT_MAX_QUEUE);
824 }
825}
826
827/* Lookup a script in the scripts queue via pid, and returns the list node
828 * (so that we can easily remove it from the queue if needed). */

Callers 2

sentinelEventFunction · 0.85

Calls 7

sdsnewFunction · 0.85
zmallocFunction · 0.85
listAddNodeTailFunction · 0.85
listRewindFunction · 0.85
listNextFunction · 0.85
listDelNodeFunction · 0.85
sentinelReleaseScriptJobFunction · 0.85

Tested by

no test coverage detected