From: SourceForge.net <no...@so...> - 2005-02-24 16:07:05
|
Feature Requests item #1120167, was opened at 2005-02-10 17:13 Message generated for change (Comment added) made by seryakov You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=719009&aid=1120167&group_id=130646 Category: None Group: None >Status: Closed Resolution: None Priority: 5 Submitted By: Vlad Seryakov (seryakov) Assigned to: Vlad Seryakov (seryakov) Summary: Cron like scheduler Initial Comment: I have working cron-like scheduer as Tcl command for other project and it makes real difference in doing background tasks. Current AS schedule_proc functionality is fine but not flexible, having it as unix cron would give real opportunities to run tasks from AS, not using UNIX cron in addition. I have code, it is very small and simple, i was surpised myself when i have it done. I am just not sure is it better be new command or extend ns_schedule_proc with additional switches. Currently, syntax is somethign like this: ns_cron script -id id -enable 0|1 -once 0|1 -thread 0|1 -min N -hour N -day N -mon N -year N -dow N -interval N -min|hour|mon|day|year|dow can be repeated. ---------------------------------------------------------------------- >Comment By: Vlad Seryakov (seryakov) Date: 2005-02-24 16:07 Message: Logged In: YES user_id=184124 It is duplication of current schedule, no need to add at this time ---------------------------------------------------------------------- Comment By: Vlad Seryakov (seryakov) Date: 2005-02-11 14:12 Message: Logged In: YES user_id=184124 This is Tcl command, parsing isn't that hard assuming that everything comes as switch value pairs. It is C+++, but converting to use Tcl hases instead of queue is simple. ------------------------------------------------------------- case cmdSchedule: { if(objc < 3) { Tcl_WrongNumArgs(interp,2,objv,"script ?-id id? ?-min mins? ?-hour hrs? ?-day day? ?-mon mon? ?-year year? ?-dow dow? ?-interval secs? ?-thread 0|1? ?-once 0|1? ?-enable 0|1? ?-remove 1?"); return TCL_ERROR; } Schedule *sched = 0; for(int i = 3;i < objc - 1;i += 2) { if(!strcmp(Tcl_GetString(objv[i]),"-min")) { int v = atoi(Tcl_GetString(objv[i+1])); if(v < 0 || v >= 60) continue; if(!sched) sched = new Schedule(); sched->min[v] = 1; sched->min[sizeof(sched->min)-1] = 1; } else if(!strcmp(Tcl_GetString(objv[i]),"-hour")) { int v = atoi(Tcl_GetString(objv[i+1])); if(v < 0 ||v >= 24) continue; if(!sched) sched = new Schedule(); sched->hour[v] = 1; sched->hour[sizeof(sched->hour)-1] = 1; } else if(!strcmp(Tcl_GetString(objv[i]),"-day")) { int v = atoi(Tcl_GetString(objv[i+1])); if(v < 0 || v >= 32) continue; if(!sched) sched = new Schedule(); sched->mday[v] = 1; sched->mday[sizeof(sched->mday)-1] = 1; } else if(!strcmp(Tcl_GetString(objv[i]),"-mon")) { int v = atoi(Tcl_GetString(objv[i+1])); if(v < 1 || v > 12) continue; if(!sched) sched = new Schedule(); sched->mon[v-1] = 1; sched->mon[sizeof(sched->mon)-1] = 1; } else if(!strcmp(Tcl_GetString(objv[i]),"-year")) { int v = atoi(Tcl_GetString(objv[i+1])); if(v < 2005 || v >= 2015) continue; if(!sched) sched = new Schedule(); sched->year[v-2005] = 1; sched->year[sizeof(sched->year)-1] = 1; } else if(!strcmp(Tcl_GetString(objv[i]),"-dow")) { int v = atoi(Tcl_GetString(objv[i+1])); if(v < 0 || v >= 7) continue; if(!sched) sched = new Schedule(); sched->wday[v] = 1; sched->wday[sizeof(sched->wday)-1] = 1; } else if(!strcmp(Tcl_GetString(objv[i]),"-interval")) { if(!sched) sched = new Schedule(); sched->interval = atoi(Tcl_GetString(objv[i+1])); } else if(!strcmp(Tcl_GetString(objv[i]),"-thread")) { if(!sched) sched = new Schedule(); sched->thread_flag = atoi(Tcl_GetString(objv[i+1])); } else if(!strcmp(Tcl_GetString(objv[i]),"-once")) { if(!sched) sched = new Schedule(); sched->once_flag = atoi(Tcl_GetString(objv[i+1])); } else if(!strcmp(Tcl_GetString(objv[i]),"-enable")) { if(!sched) sched = new Schedule(); sched->enable_flag = atoi(Tcl_GetString(objv[i+1])); } else if(!strcmp(Tcl_GetString(objv[i]),"-remove")) { if(sched) delete sched; sched = 0; return TCL_OK; } else if(!strcmp(Tcl_GetString(objv[i]),"-id")) { if(sched) delete sched; int id = atoi(Tcl_GetString(objv[i+1])); vector<Schedule*>::iterator iter; pthread_mutex_lock(&schedmutex); for(iter = schedqueue.begin();iter != schedqueue.end();iter++) { sched = *iter; if(sched->id == id) { schedqueue.erase(iter); break; } } pthread_mutex_unlock(&schedmutex); if(iter == schedqueue.end()) { Tcl_AppendResult(interp,"schedule id not found",0); return TCL_ERROR; } } } if(!sched || sched->Setup()) { Tcl_AppendResult(interp,"unable to setup schedule, no date/time given",0); return TCL_ERROR; } sched->script = Tcl_GetString(objv[2]); pthread_mutex_lock(&schedmutex); schedqueue.push_back(sched); pthread_mutex_unlock(&schedmutex); Tcl_SetObjResult(interp,Tcl_NewIntObj(sched->id)); } ---------------------------------------------------------------------- Comment By: Stephen Deasey (sdeasey) Date: 2005-02-11 04:05 Message: Logged In: YES user_id=87254 That's a lot of switches to parse, you should check out my new Ns_ParseObjv (when I get it posted...) ! Hmm, not sure what the best api would be. It would be nice to have everything integrated with the sched stuff that's already there. The switch parsing for NsTclSchedCmd looks scary though :-) You've both already tackled this though, so looks like a good candidate for inclusion. Sounds good to me. ---------------------------------------------------------------------- Comment By: Vlad Seryakov (seryakov) Date: 2005-02-10 17:27 Message: Logged In: YES user_id=184124 No, it is C module for use in Tcl, not pure Tcl implementation, i use it in C application with embedded Tcl for scripting. Once i get to my home and reincarnate dialup or bring it on laptop tomorrow, it sucks to be without Internet at home. ---------------------------------------------------------------------- Comment By: Zoran Vasiljevic (vasiljevic) Date: 2005-02-10 17:23 Message: Logged In: YES user_id=95086 All Tcl? Care to attach the implementation? I also had the need for this and did it myself i Tcl as well (hey, we're masters in reinventing the wheel!) I think the reason to implement this in core server as C-code was the idea to be able to use it from the C-API as well w/o being dependent on some Tcl code from outside. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=719009&aid=1120167&group_id=130646 |