11/**
22 * @module Framework
3- * @version 1.8.1
3+ * @version 1.9.0
44 */
55
66'use strict' ;
@@ -142,8 +142,8 @@ global.ROUTING = function(name) {
142142 return framework . routing ( name ) ;
143143} ;
144144
145- global . SCHEDULE = function ( date , fn ) {
146- return framework . schedule ( date , fn ) ;
145+ global . SCHEDULE = function ( date , each , fn ) {
146+ return framework . schedule ( date , each , fn ) ;
147147} ;
148148
149149global . FINISHED = function ( stream , callback ) {
@@ -197,8 +197,8 @@ global.is_server = true;
197197function Framework ( ) {
198198
199199 this . id = null ;
200- this . version = 1810 ;
201- this . version_header = '1.8.1-48 ' ;
200+ this . version = 1900 ;
201+ this . version_header = '1.9.0-1 ' ;
202202
203203 var version = process . version . toString ( ) . replace ( 'v' , '' ) . replace ( / \. / g, '' ) ;
204204 if ( version [ 1 ] === '0' )
@@ -292,7 +292,7 @@ function Framework() {
292292 this . connections = { } ;
293293 this . functions = { } ;
294294 this . versions = null ;
295- this . schedules = { } ;
295+ this . schedules = [ ] ;
296296
297297 this . isDebug = true ;
298298 this . isTest = false ;
@@ -411,7 +411,6 @@ function Framework() {
411411 this . _length_middleware = 0 ;
412412 this . _length_request_middleware = 0 ;
413413 this . _length_files = 0 ;
414- this . _schedules = false ;
415414
416415 this . isVirtualDirectory = false ;
417416 this . isWindows = os . platform ( ) . substring ( 0 , 3 ) . toLowerCase ( ) === 'win' ;
@@ -625,10 +624,16 @@ Framework.prototype.redirect = function(host, newHost, withPath, permanent) {
625624/**
626625 * Schedule job
627626 * @param {Date or String } date
627+ * @param {Boolean } repeat Repeat schedule
628628 * @param {Function } fn
629629 * @return {Framework }
630630 */
631- Framework . prototype . schedule = function ( date , fn ) {
631+ Framework . prototype . schedule = function ( date , repeat , fn ) {
632+
633+ if ( fn === undefined ) {
634+ fn = repeat ;
635+ repeat = false ;
636+ }
632637
633638 var self = this ;
634639 var type = typeof ( date ) ;
@@ -639,11 +644,12 @@ Framework.prototype.schedule = function(date, fn) {
639644 date = new Date ( date ) ;
640645
641646 var sum = date . getTime ( ) ;
642- var id = Utils . GUID ( 5 ) + Utils . random ( 10000 ) ;
647+ var id = framework_utils . GUID ( 5 ) + framework_utils . random ( 10000 ) ;
643648
644- self . schedules [ id ] = { expire : sum , fn : fn } ;
645- self . _schedules = true ;
649+ if ( repeat )
650+ repeat = repeat . replace ( 'each' , '1' ) ;
646651
652+ self . schedules . push ( { expire : sum , fn : fn , repeat : repeat } ) ;
647653 return self ;
648654} ;
649655
@@ -1268,7 +1274,7 @@ Framework.prototype.middleware = function(name, funcExecute) {
12681274Framework . prototype . use = function ( name ) {
12691275 var self = this ;
12701276
1271- if ( arguments . length > 0 ) {
1277+ if ( arguments . length ) {
12721278 for ( var i = 0 ; i < arguments . length ; i ++ )
12731279 self . routes . request . push ( arguments [ i ] ) ;
12741280 } else if ( name instanceof Array ) {
@@ -2287,7 +2293,7 @@ Framework.prototype.install_prepare = function(noRecursive) {
22872293 clearTimeout ( self . temporary . other . dependencies ) ;
22882294 self . temporary . other . dependencies = setTimeout ( function ( ) {
22892295 var keys = Object . keys ( framework . temporary . dependencies ) ;
2290- if ( keys . length > 0 )
2296+ if ( keys . length )
22912297 throw new Error ( 'Dependency exception (module): missing dependencies for: ' + keys . join ( ', ' ) . trim ( ) ) ;
22922298 delete self . temporary . other . dependencies ;
22932299 } , 1500 ) ;
@@ -2731,7 +2737,6 @@ Framework.prototype.usage = function(detailed) {
27312737 var modules = Object . keys ( self . modules ) ;
27322738 var isomorphic = Object . keys ( self . isomorphic ) ;
27332739 var models = Object . keys ( self . models ) ;
2734- var schedules = Object . keys ( self . schedules ) ;
27352740 var helpers = Object . keys ( self . helpers ) ;
27362741 var staticFiles = Object . keys ( self . temporary . path ) ;
27372742 var staticRange = Object . keys ( self . temporary . range ) ;
@@ -2766,7 +2771,7 @@ Framework.prototype.usage = function(detailed) {
27662771 cache : cache . length ,
27672772 worker : workers . length ,
27682773 connection : connections . length ,
2769- schedule : schedules . length ,
2774+ schedule : self . schedules . length ,
27702775 helpers : helpers . length ,
27712776 error : self . errors . length ,
27722777 problem : self . problems . length ,
@@ -4864,29 +4869,32 @@ Framework.prototype._service = function(count) {
48644869
48654870 self . emit ( 'service' , count ) ;
48664871
4872+ var length = self . schedules . length ;
4873+
48674874 // Run schedules
4868- if ( ! self . _schedules )
4875+ if ( ! length )
48694876 return self ;
48704877
48714878 var expire = new Date ( ) . getTime ( ) ;
4872- var pending = false ;
4873-
4874- // F.schedules() sets this property to true
4875- self . _schedules = false ;
4879+ var index = 0 ;
48764880
4877- for ( var key in self . schedules ) {
4878- var obj = self . schedules [ key ] ;
4879- if ( obj . expire > expire ) {
4880- pending = true ;
4881+ while ( true ) {
4882+ var schedule = self . schedules [ index ++ ] ;
4883+ if ( ! schedule )
4884+ break ;
4885+ if ( schedule . expire > expire )
48814886 continue ;
4882- }
4883- delete self . schedules [ key ] ;
4887+
4888+ index -- ;
4889+
4890+ if ( ! schedule . repeat )
4891+ self . schedules . splice ( index , 1 ) ;
4892+ else
4893+ schedule . expire = new Date ( ) . add ( schedule . repeat ) ;
4894+
48844895 obj . fn . call ( self ) ;
48854896 }
48864897
4887- if ( pending )
4888- self . _schedules = true ;
4889-
48904898 return self ;
48914899} ;
48924900
@@ -5324,7 +5332,7 @@ Framework.prototype._upgrade_continue = function(route, req, path) {
53245332 return self ;
53255333 }
53265334
5327- var id = path + ( route . flags . length > 0 ? '#' + route . flags . join ( '-' ) : '' ) ;
5335+ var id = path + ( route . flags . length ? '#' + route . flags . join ( '-' ) : '' ) ;
53285336
53295337 if ( route . isBINARY )
53305338 socket . type = 1 ;
@@ -5336,12 +5344,12 @@ Framework.prototype._upgrade_continue = function(route, req, path) {
53365344 var connection = new WebSocket ( self , path , route . controller , id ) ;
53375345 connection . route = route ;
53385346 self . connections [ id ] = connection ;
5339- route . onInitialize . apply ( connection , framework_internal . routeParam ( route . param . length > 0 ? framework_internal . routeSplit ( req . uri . pathname , true ) : req . path , route ) ) ;
5347+ route . onInitialize . apply ( connection , framework_internal . routeParam ( route . param . length ? framework_internal . routeSplit ( req . uri . pathname , true ) : req . path , route ) ) ;
53405348 }
53415349 socket . upgrade ( self . connections [ id ] ) ;
53425350 } ;
53435351
5344- if ( route . middleware instanceof Array && route . middleware . length > 0 ) {
5352+ if ( route . middleware instanceof Array && route . middleware . length ) {
53455353 var func = new Array ( route . middleware . length ) ;
53465354 var indexer = 0 ;
53475355 for ( var i = 0 , length = route . middleware . length ; i < length ; i ++ ) {
@@ -5623,7 +5631,7 @@ Framework.prototype.assert = function(name, url, flags, callback, data, cookies,
56235631 for ( var i = 0 ; i < length ; i ++ )
56245632 builder . push ( keys [ i ] + '=' + encodeURIComponent ( cookies [ keys [ i ] ] ) ) ;
56255633
5626- if ( builder . length > 0 )
5634+ if ( builder . length )
56275635 headers [ 'Cookie' ] = builder . join ( '; ' ) ;
56285636 }
56295637
@@ -5771,7 +5779,7 @@ Framework.prototype.testing = function(stop, callback) {
57715779
57725780 var buf ;
57735781
5774- if ( test . data && test . data . length > 0 ) {
5782+ if ( test . data && test . data . length ) {
57755783 buf = new Buffer ( test . data , ENCODING ) ;
57765784 test . headers [ RESPONSE_HEADER_CONTENTLENGTH ] = buf . length ;
57775785 }
@@ -5881,7 +5889,7 @@ Framework.prototype.test = function(stop, names, cb) {
58815889 if ( ext !== EXTENSION_JS )
58825890 return ;
58835891
5884- if ( names . length > 0 && names . indexOf ( name . substring ( 0 , name . length - 3 ) ) === - 1 )
5892+ if ( names . length && names . indexOf ( name . substring ( 0 , name . length - 3 ) ) === - 1 )
58855893 return ;
58865894
58875895 var test = require ( filename ) ;
@@ -6562,7 +6570,7 @@ Framework.prototype._configure = function(arr, rewrite) {
65626570 if ( self . config [ 'default-timezone' ] )
65636571 process . env . TZ = self . config [ 'default-timezone' ] ;
65646572
6565- if ( accepts !== null && accepts . length > 0 ) {
6573+ if ( accepts !== null && accepts . length ) {
65666574 accepts . forEach ( function ( accept ) {
65676575 self . config [ 'static-accepts' ] [ accept ] = true ;
65686576 } ) ;
@@ -6799,7 +6807,7 @@ Framework.prototype.lookup = function(req, url, flags, noLoggedUnlogged) {
67996807 continue ;
68006808 }
68016809
6802- if ( route . flags !== null && route . flags . length > 0 ) {
6810+ if ( route . flags !== null && route . flags . length ) {
68036811 var result = framework_internal . routeCompareFlags2 ( req , route , noLoggedUnlogged ? true : route . isMEMBER ) ;
68046812 if ( result === - 1 )
68056813 req . $isAuthorized = false ; // request is not authorized
@@ -6869,7 +6877,7 @@ Framework.prototype.lookup_websocket = function(req, url, noLoggedUnlogged) {
68696877 continue ;
68706878 }
68716879
6872- if ( route . flags !== null && route . flags . length > 0 ) {
6880+ if ( route . flags !== null && route . flags . length ) {
68736881
68746882 // var result = framework_internal.routeCompareFlags(req.flags, route.flags, noLoggedUnlogged ? true : route.isMEMBER);
68756883 var result = framework_internal . routeCompareFlags2 ( req , route , noLoggedUnlogged ? true : route . isMEMBER ) ;
@@ -8197,9 +8205,9 @@ Subscribe.prototype.doExecute = function() {
81978205 return self ;
81988206
81998207 if ( self . route . isGENERATOR )
8200- async . call ( controller , self . route . execute , true ) ( controller , framework_internal . routeParam ( self . route . param . length > 0 ? framework_internal . routeSplit ( req . uri . pathname , true ) : req . path , self . route ) ) ;
8208+ async . call ( controller , self . route . execute , true ) ( controller , framework_internal . routeParam ( self . route . param . length ? framework_internal . routeSplit ( req . uri . pathname , true ) : req . path , self . route ) ) ;
82018209 else
8202- self . route . execute . apply ( controller , framework_internal . routeParam ( self . route . param . length > 0 ? framework_internal . routeSplit ( req . uri . pathname , true ) : req . path , self . route ) ) ;
8210+ self . route . execute . apply ( controller , framework_internal . routeParam ( self . route . param . length ? framework_internal . routeSplit ( req . uri . pathname , true ) : req . path , self . route ) ) ;
82038211
82048212 return self ;
82058213
@@ -9113,7 +9121,7 @@ Controller.prototype.transfer = function(url, flags) {
91139121 break ;
91149122 }
91159123
9116- if ( route . flags !== null && route . flags . length > 0 ) {
9124+ if ( route . flags !== null && route . flags . length ) {
91179125 var result = framework_internal . routeCompareFlags ( route . flags , flags , true ) ;
91189126 if ( result === - 1 )
91199127 self . req . $isAuthorized = false ;
@@ -12296,7 +12304,7 @@ WebSocketClient.prototype.prepare = function(flags, protocols, allow, length, ve
1229612304
1229712305 var origin = self . req . headers [ 'origin' ] || '' ;
1229812306
12299- if ( allow . length > 0 ) {
12307+ if ( allow . length ) {
1230012308
1230112309 if ( allow . indexOf ( '*' ) === - 1 ) {
1230212310 for ( var i = 0 ; i < allow . length ; i ++ ) {
@@ -12311,7 +12319,7 @@ WebSocketClient.prototype.prepare = function(flags, protocols, allow, length, ve
1231112319 return false ;
1231212320 }
1231312321
12314- if ( protocols . length > 0 ) {
12322+ if ( protocols . length ) {
1231512323 for ( var i = 0 ; i < protocols . length ; i ++ ) {
1231612324 if ( self . protocol . indexOf ( protocols [ i ] ) === - 1 )
1231712325 return false ;
0 commit comments