--将plat_lis数据库中的日志文件收缩到 1 MB。 USE testDB; GO -- 通过将数据库恢复模型更改为 SIMPLE 来截断日志。 ALTER DATABASE testDB SET RECOVERY SIMPLE; GO -- Shrink the truncated log file to 1 MB. DBCC SHRINKFILE (testDB_log, 1); GO -- 重置数据库恢复模式。 ALTER DATABASE testDB SET RECOVERY FULL; GO
q.UseInMemoryStore(); q.UseDefaultThreadPool(tp => { tp.MaxConcurrency = 10; }); //Use a Scoped container to create jobs. I'll touch on this later q.UseMicrosoftDependencyInjectionJobFactory();
// Create a "key" for the job var jobKey = new JobKey("TestJob"); // Register the job with the DI container q.AddJob<TestJob>(opts => opts.WithIdentity(jobKey)); // Create a trigger for the job q.AddTrigger(opts => opts .ForJob(jobKey) // link to the HelloWorldJob .WithIdentity("HelloWorldJob-trigger") // give the trigger a unique name .WithCronSchedule("0/5 * * * * ?")); // run every 5 seconds
var start = Date.now();//获取当前时间戳 setTimeout(function () { console.log(Date.now() - start); for (var i = 0; i < 1000000000; i++){//执行长循环 } }, 1000); setTimeout(function () { console.log(Date.now() - start); }, 2000);
最终我们的打印结果是:(结果可能因为你的机器而不同)
1 2
1000 3738
对于我们期望2秒后执行的setTimeout函数其实经过了3738毫秒之后才执行,换而言之,因为执行了一个很长的for循环,所以我们整个Node.js主线程被阻塞了,如果在我们处理100个用户请求中,其中第一个有需要这样大量的计算,那么其余99个就都会被延迟执行。如果操作系统本身就是单核,那也就算了,但现在大部分服务器都是多 CPU 或多核的,而 Node.js 只有一个 EventLoop,也就是只占用一个 CPU 内核,当 Node.js 被CPU 密集型任务占用,导致其他任务被阻塞时,却还有 CPU 内核处于闲置状态,造成资源浪费。
webpack是一个工具,这个工具可以帮你处理好各个包/模块之间的依赖关系(modules with dependencies),并将这些复杂依赖关系的静态文件打包成一个或很少的静态文件,提供给浏览器访问使用;除此之外,webpack因为可以提高兼容性,可以将一些浏览器尚不支持的新特性转换为可以支持格式,进而减少由新特性带来的浏览器的兼容性问题
Node.js is an open-source and cross-platform JavaScript runtime environment. It is a popular tool for almost any kind of project!
Node.js runs the V8 JavaScript engine, the core of Google Chrome, outside of the browser. This allows Node.js to be very performant.
A Node.js app runs in a single process, without creating a new thread for every request. Node.js provides a set of asynchronous I/O primitives in its standard library that prevent JavaScript code from blocking and generally, libraries in Node.js are written using non-blocking paradigms, making blocking behavior the exception rather than the norm.
When Node.js performs an I/O operation, like reading from the network, accessing a database or the filesystem, instead of blocking the thread and wasting CPU cycles waiting, Node.js will resume the operations when the response comes back.
This allows Node.js to handle thousands of concurrent connections with a single server without introducing the burden of managing thread concurrency, which could be a significant source of bugs.
Node.js has a unique advantage because millions of frontend developers that write JavaScript for the browser are now able to write the server-side code in addition to the client-side code without the need to learn a completely different language.
In Node.js the new ECMAScript standards can be used without problems, as you don't have to wait for all your users to update their browsers - you are in charge of deciding which ECMAScript version to use by changing the Node.js version, and you can also enable specific experimental features by running Node.js with flags.
Introduction to npm npm is the standard package manager for Node.js.
In January 2017 over 350000 packages were reported being listed in >the npm registry, making it the biggest single language code >repository on Earth, and you can be sure there is a package for >(almost!) everything.
It started as a way to download and manage dependencies of Node.js >packages, but it has since become a tool used also in frontend >JavaScript.
There are many things that npm does.
Yarn and pnpm are alternatives to npm cli. You can check them out as >well.
var str1= "Hello Pentaho!"; var str2= indexOf(str1, "Pentaho"); var str3= indexOf(str1, "o", 7); writeToLog("Input : " + str1); writeToLog("Index of 'Pentaho' : " + str2); writeToLog("index of 'o', search from position 7 : " + str3);
最终控制台输出:
1 2 3
2019/08/1910:34:16 - JavaScript代码.0 - Input : Hello Pentaho! 2019/08/1910:34:16 - JavaScript代码.0 - Index of 'Pentaho' : 6 2019/08/1910:34:16 - JavaScript代码.0 - index of 'o', search from position 7 : 12
首字母大写(initCap)
对指定字符串首字母大写处理,来看代码示例:
1 2 3 4
var str1 = "my home"; writeToLog(initCap(str1)); writeToLog(initCap('test a aaa cw')); writeToLog(initCap('myhome'));
此时,最终控制台输出如下:
1 2 3
2019/08/1910:41:27 - JavaScript代码.0 - My Home 2019/08/1910:41:27 - JavaScript代码.0 - Test A Aaa Cw 2019/08/1910:41:27 - JavaScript代码.0 - Myhome
字符串转小写(lower)
将传入字符串全部转小写
代码如下:
1 2 3 4 5
var str1= "Hello World!"; var str2= lower(str1); writeToLog("Input:" + str1); writeToLog("Converted to LowerCase:" + str2); writeToLog(lower('DDDHelloSWxss'))
var str1 = "Hello World, this is a nice function"; var str2 = replace(str1,"World", "Folk"); writeToLog(str2); var str2 = replace(str1,"World", "Folk", "nice","beautifull"); writeToLog(str2);
最终输出:
1 2
2019/08/1911:10:21 - JavaScript代码.0 - Hello Folk, this is a nice function 2019/08/1911:10:21 - JavaScript代码.0 - Hello Folk, this is a beautifull function
字符串右侧填充(rpad(string,char,length))
使用方法同lpad,只是一个是左侧,一个是右侧
去除空字符(右侧)(rtrim)
正则切分(str2RegExp)
出入一个正则表达式,对string字符串进行Split操作.代码如下:
1 2 3 4 5 6 7 8 9 10 11 12
var strToMatch = "info@proconis.de"; var strReg = "^(\\w+)@([a-zA-Z_]+?)\\.([a-zA-Z]{2,3})$"; var xArr = str2RegExp(strToMatch, strReg); if ( xArr != null ) { for(i=0;i<xArr.length;i++) { writeToLog(xArr[i]); } } else { writeToLog("no match"); }
最终控制台输出:
1 2 3
2019/08/1913:21:19 - JavaScript代码.0 - info 2019/08/1913:21:19 - JavaScript代码.0 - proconis 2019/08/1913:21:19 - JavaScript代码.0 - de
字符串截取(substr)
通过制定索引开始对字符串进行截取操作,主要有两个重构参数:
substr(string,from):指定from索引开始截取字符串
substr(string,from,to):指定开始和截止索引进行截取
代码示例:
1 2 3 4 5 6
var str1= "Hello Pentaho!"; var str2= substr(str1, 6); var str3= substr(str1, 6, 7); writeToLog("Input : " + str1); writeToLog("From position 6: " + str2); writeToLog("From position 6 for 7 long : " + str3);
控制台输出如下:
1 2 3
2019/08/1913:31:20 - JavaScript代码.0 - Input : Hello Pentaho! 2019/08/1913:31:20 - JavaScript代码.0 - From position 6: Pentaho! 2019/08/1913:31:20 - JavaScript代码.0 - From position 6for7long : Pentaho
去除左右空格(trim)
不转义HTML(unEscapeHtml(html))
针对以转义的HTML字符进行解密,代码如下:
1 2 3 4 5 6 7
var w='<h2>我是H2标题</h2>';
var esW=escapeHtml(w); var unesw=unEscapeHtml(esW);
// Returns the fiscal Date from the date value, // based on a given offset. // // Usage: // getFiscalDate(var); // 1: Date - The Variable with the Date. // 2: String - The Date/Month which represents // the fiscal Start Offset. Format allways "dd.MM.". // // 2006-11-15 // var d1 = newDate(); var str1 = "01.07."; var str2 = "10.12."; Alert(getFiscalDate(d1, str1)); Alert(getFiscalDate(d1, str2));
获取下一个工作日日期(getNextWorkingDay)
传入当前日期,获取该日期后面一个工作日日期
函数定义getNextWorkingDay(date)
代码示例如下:
1 2 3 4 5 6 7 8 9 10
var d1 = newDate();
// 周1 var d2=str2date('2019-08-19 16:36:00',fmt); //周 6 var d3=str2date('2019-08-17 16:36:00',fmt);
var dateTime = newDate(); var date0 = truncDate(dateTime, 0); // gives back today at yyyy/MM/dd HH:mm:ss.000 var date1 = truncDate(dateTime, 1); // gives back today at yyyy/MM/dd HH:mm:00.000 var date2 = truncDate(dateTime, 2); // gives back today at yyyy/MM/dd HH:00:00.000 var date3 = truncDate(dateTime, 3); // gives back today at yyyy/MM/dd 00:00:00.000 var date4 = truncDate(dateTime, 4); // gives back today at yyyy/MM/01 00:00:00.000 var date5 = truncDate(dateTime, 5); // gives back today at yyyy/01/01 00:00:00.000
获取当年的周数(week)
获取指定日期的周数,代码示例:
1 2 3
var d1 = newDate(); //2019/08/19 writeToLog(week(d1));// 返回34
获取年份(year)
获取传入日期的年份,代码示例:
1 2 3
var d1 = newDate(); //2019/08/19 writeToLog(year(d1));// 返回2019
var strVarName="getVariableTest"; var strVarValue="123456"; Alert(getVariable(strVarName, "")); setVariable(strVarName,strVarValue, "r"); Alert(getVariable(strVarName, "")); strVarValue="654321"; setVariable(strVarName,strVarValue, "r"); Alert(getVariable(strVarName, ""));
控制台打印(println)
1 2 3
var str = "Hello World!"; print(str);
移除数值(removeDigits)
移除给定字符串中的数值,代码示例:
1 2 3
var str1 = "abc123cde";
writeToLog(removeDigits(str1));//返回abccde
发送邮件
设置环境变量(setEnvironmentVar)
通过在Script脚本组件中调用函数重新设置Kettle的环境变量
1 2 3 4 5 6 7 8
var strVarName="setEnvTest"; var strVarValue="123456"; Alert(getEnvironmentVar(strVarName)); setEnvironmentVar(strVarName,strVarValue); Alert(getEnvironmentVar(strVarName)); strVarValue="654321"; setEnvironmentVar(strVarName,strVarValue); Alert(getEnvironmentVar(strVarName));