FCLT#86661 Savepoint global tsk_master_schema voor scheduling

svn path=/Website/trunk/; revision=67372
This commit is contained in:
Jos Groot Lipman
2024-12-12 08:17:30 +00:00
parent 6de7813917
commit fa52d77f78
17 changed files with 420 additions and 46 deletions

View File

@@ -70,6 +70,8 @@ function gettablesql(ptable, pchildtable, pchildsql, precord, pmtable)
var pwhere_veldnaam = "";
if (ptable == "prs_perslid")
{
user.checkAutorisation(["WEB_FACMSU", "WEB_PRSMSU", "WEB_PRSSYS"]);
model_fac_audit.autfunction = false;
var pfac_audit_tabelkey = " (SELECT fac.safe_to_number (x.fac_audit_waarde_oud)"
+ " FROM fac_audit x"
+ " WHERE x.fac_audit_veldnaam = 'prs_perslid_key'"

View File

@@ -8,12 +8,68 @@
var model = model_generic(table, "WEB_FACTAB");
var puo_const = { STATUS_PORTAL: 1 // Niet via Putorders.exe
, STATUS_EMAIL: 2
, STATUS_SMS: 4
, STATUS_POPUP: 8 // Niet via Putorders.exe
, STATUS_SUMMARY_XSL: 16 // SMS/Email subject via XSL?
, STATUS_APPPUSH: 32 // Naar Azure app
, STATUS_CUST: 64
};
api2.generic_REST(model);
// Voorkennis:
model.fields["prs_perslid_key_sender"].typ = "key";
model.fields["prs_perslid_key_sender"].foreign = "PRS_PERSLID";
model.fields["prs_perslid_key_receiver"].typ = "key";
model.fields["prs_perslid_key_receiver"].foreign = "PRS_PERSLID";
model.fields["fac_notificatie_status"].bits =
[
{
"name": "",
"label": "",
"typ": "check",
"mask": 127,
"radios": [
{
"name": "flag_portal",
"label": "Portal",
"mask": puo_const.STATUS_PORTAL,
"defaultvalue": 0
},
{ "name": "flag_email",
"label": "E-mail",
"mask": puo_const.STATUS_EMAIL,
"defaultvalue": 0
},
{ "name": "flag_sms",
"label": "SMS",
"mask": puo_const.STATUS_SMS,
"defaultvalue": 0
},
{ "name": "flag_popup",
"label": "Popup",
"mask": puo_const.STATUS_POPUP,
"defaultvalue": 0
},
{ "name": "flag_summaryxsl",
"label": "Summary-XSL",
"mask": puo_const.STATUS_SUMMARY_XSL,
"defaultvalue": 0
},
{ "name": "flag_apppush",
"label": "APP Push",
"mask": puo_const.STATUS_APPPUSH,
"defaultvalue": 0
},
{ "name": "flag_cust",
"label": "Custom",
"mask": puo_const.STATUS_CUST,
"defaultvalue": 0
}
]
}
]
for (var fld in model.fields)
{
@@ -44,8 +100,19 @@
"fac_notificatie_systeemadres",
"prs_bedrijfadres_key",
"fac_notificatie_failcount",
"fac_notificatie_faildatum",
"fac_notificatie_failmessage"
]
],
rowClass: function(oRs)
{
if (oRs.Fields("fac_notificatie_status").Value == 0 &&
oRs.Fields("fac_notificatie_systeemadres").Value == null &&
oRs.Fields("prs_bedrijfadres_key").Value == null)
{
return "lowlight"; // valt niets te versturen
}
return null;
}
},
"show": {

View File

@@ -5,7 +5,7 @@
function send_immediate(key)
{
FcltMgr.confirm("Notificatie geforceerd immediate versturen?\nHij wordt niet verwijderd uit de queue. Overrules blijven gewoon van toepassing.",
FcltMgr.confirm("Notificatie geforceerd versturen?",
function() {
var data = { "fac_notificatie_key": key };
protectRequest.dataToken(data);

View File

@@ -4,7 +4,7 @@
$Id$
File: fac_notificatie_immediate.asp.asp
Description: Stuur een test notificatie naar alle apps van de gebruiker
Description: Forceer een putorders run
Parameters:
Context:
Note:
@@ -20,10 +20,13 @@ protectRequest.validateToken();
user.auth_required_or_abort(user.has("WEB_FACTAB"));
var fac_notificatie_key = getFParamInt("fac_notificatie_key");
var sql = "UPDATE fac_notificatie"
+ " SET fac_notificatie_notbefore = SYSDATE";
Oracle.Execute(sql)
var sql = "BEGIN tsk.startputorders(SYSDATE); END;"; // triggert alleen op Insert, niet op Update
Oracle.Execute(sql)
var puo_result = putorders.sendnotificationforced(fac_notificatie_key);
var result = { success: true, message: puo_result.message };
var result = { success: true, message: "Putorders has been activated" };
Response.Write(JSON.stringify(result));
%><% ASPPAGE_END(); %>

65
APPL/MGT/fac_task.asp Normal file
View File

@@ -0,0 +1,65 @@
<%@language = "javascript" %>
<!-- #include file="../scf/scaffolding.inc" -->
<!-- #include file="../api2/model_generic.inc" -->
<%
var table = "fac_task";
var model = model_generic(table, "WEB_FACTAB");
api2.generic_REST(model);
// Voorkennis:
model.fields["fac_cust_key"].typ = "key";
model.fields["fac_cust_key"].foreign = { tbl: "fac_cust", key: "fac_cust_key", desc: "fac_cust_customerid"};
model.fields["fac_task_nextrun"].multiedit = true;
for (var fld in model.fields)
{
model.fields[fld].label = model.fields[fld].label.replace("fac_task_", ""); // iets kortere labels
}
scaffolding(model, {
"search": {
"autosearch": true,
"filters": [
"name",
"fac_cust_key"
]
},
"list": {
"columns": [
"id",
"fac_cust_key",
"name", // is fac_task_code
"fac_task_nextrun",
"fac_task_lastrun"
],
rowClass: function(oRs)
{
if (oRs.Fields("fac_notificatie_status").Value == 0 &&
oRs.Fields("fac_notificatie_systeemadres").Value == null &&
oRs.Fields("prs_bedrijfadres_key").Value == null)
{
return "lowlight";
}
return null;
}
},
"Xshow": {
"buttons": [
{ icon: "fa-send", title: "Immediate", tooltip: "Send immediate", action: "send_immediate" }
],
"requires": {
js: ["./fac_notificatie.js"]
}
},
"layout": {
"miscellaneous": {
"icon": "fa-clock"
}
}
});
%>
<% ASPPAGE_END(); %>

View File

@@ -9,7 +9,7 @@
Context:
Notes:
Notes: Wordt nu ook gedaan vanuit mld_kenmerk ??
*/
%>
<!-- #include file="../scf/scaffolding.inc" -->

View File

@@ -1779,13 +1779,10 @@ res = {
+ ((params.activiteit_key || params.act_key_arr.length > 0)
? " AND EXISTS (SELECT res_activiteit_key FROM res_activiteitdiscipline rad"
+ " WHERE rad.res_discipline_key = rg.res_discipline_key"
+ ( params.activiteit_key
? " AND rad.res_activiteit_key = " + params.activiteit_key + ")"
: ( params.act_key_arr.length > 0
? " AND rad.res_activiteit_key IN (" + params.act_key_arr.join(",") + "))"
: ""
)
)
+ (params.activiteit_key
? " AND rad.res_activiteit_key = " + params.activiteit_key
: " AND rad.res_activiteit_key IN (" + params.act_key_arr.join(",") + ")")
+ ")"
: "")
+ ((!params.activiteit_key && params.act_key_arr.length == 0 && params.srtact > 0)
? " AND EXISTS (SELECT ra.res_activiteit_key"

View File

@@ -644,8 +644,9 @@ function scf_RWFIELDTR(model, fld, val, key, params)
}
else
{
var fieldname = (foreign.name||foreign.desc);
var sql = "SELECT " + foreign.key
+ " , " + foreign.desc
+ " , " + fieldname
+ (foreign.extravalue ? ", " + foreign.extravalue : "")
+ " FROM " + foreign.tbl + " " + (foreign.alias||"")
+ (foreign.where?" WHERE " + foreign.where:"")

View File

@@ -342,7 +342,7 @@ function scaffolding_list(model, scf_params)
title: title,
showAll: showAll,
canCSV: !nobuttons && model.list.canCSV,
rowClass: model.list.rowClass || fnRowClass,
rowClass: scf_params.list.rowClass || model.list.rowClass || fnRowClass,
rowChecked: fnRowChecked,
lastColKey: lastColKey,
rowData: scf_params.list.fnRowData,

View File

@@ -81,6 +81,24 @@ function outlookCertificateCheck() {
hook = null;
}
// In deze functie komen we in ieder geval <20><>n keer per dag ('s ochtends als de application pool opstart)
// Doe allerlei housekeeping hier.
// Let op dat niet bekend is welke user toevallig de eerste van de dag is. Daarom onafhankelijk van autorisatie
// Let op dat het wordt aangeroepen vanuit default.inc/loadSET() dus ook iedere keer als een setting wijzigt!
function fclt_register_task()
{
if (S("tsk_master_schema"))
{
var sql = "BEGIN"
+ " tsk.registercust();"
+ " tsk.registertask('PUTORDERS');"
+ "END;"
Oracle.Execute(sql);
}
}
// In deze functie komen we in ieder geval <20><>n keer per dag ('s ochtends als de application pool opstart)
// Doe allerlei housekeeping hier.
// Let op dat niet bekend is welke user toevallig de eerste van de dag is. Daarom onafhankelijk van autorisatie

View File

@@ -85,11 +85,12 @@ settings =
Application.Lock();
// Application pool restart detection
if (typeof Application("SET_INSTANCE_TIME") == "undefined")
{
var tm_start = new Date();
Application("SET_INSTANCE_TIME") = tm_start.getTime(); // Estimated application pool start
Application("SET_INSTANCE_RANDOM") = shared.random(32);
Application("SET_INSTANCE_RANDOM") = shared.random(32); // om met fac_verify te kijken of S("puo_fclt_web_url") goed staat
if (tm_start.getHours() >= 9 && tm_start.getHours() <= 17) // Tijdens kantooruren registreren we in de AiAi logger
{
var keeplog = __LogfileName;
@@ -228,6 +229,7 @@ settings =
// Op deze plek van de code komen we doorgaans eens per dag
fclt_daily();
fclt_register_task();
// set "portalert" with S("fac_portalert_XD") if available
if (S("fac_portalert_xd") != "")

View File

@@ -1830,6 +1830,11 @@ function __rsMakeTableHeader(oRs, oRsFlexData, anyMultiActions)
else
sort_class += " sorttable_numericcomma";
}
else if (columns[i].datatype == "varchar" ||
columns[i].datatype == "html")
{
sort_class += " sorttable_alpha";
}
if (columns[i].align)
html += " style='text-align:" + columns[i].align + "'";

View File

@@ -84,16 +84,18 @@ function sendNotification(ref_key, pcode, params)
+ " FROM fac_notificatie f"
+ " , fac_srtnotificatie fs"
+ " , prs_perslid p"
+ " WHERE ( BITAND (fac_notificatie_status, " + (puo_const.STATUS_EMAIL | puo_const.STATUS_SMS| puo_const.STATUS_APPPUSH) + ") > 0"
+ " OR fac_notificatie_systeemadres IS NOT NULL"
+ " OR prs_bedrijfadres_key IS NOT NULL)"
+ " AND NOT EXISTS (SELECT 1"
+ " WHERE ( BITAND (f.fac_notificatie_status, " + (puo_const.STATUS_EMAIL | puo_const.STATUS_SMS| puo_const.STATUS_APPPUSH) + ") > 0"
+ " OR f.fac_notificatie_systeemadres IS NOT NULL"
+ " OR f.prs_bedrijfadres_key IS NOT NULL)"
+ " AND NOT EXISTS (SELECT 1"
+ " FROM fac_notificatie oudere"
+ " WHERE oudere.fac_notificatie_key < f.fac_notificatie_key" // ouder
+ " WHERE ( BITAND (oudere.fac_notificatie_status, " + (puo_const.STATUS_EMAIL | puo_const.STATUS_SMS| puo_const.STATUS_APPPUSH) + ") > 0"
+ " OR oudere.fac_notificatie_systeemadres IS NOT NULL"
+ " OR oudere.prs_bedrijfadres_key IS NOT NULL)"
+ " AND oudere.fac_notificatie_key < f.fac_notificatie_key" // ouder
+ " AND oudere.prs_bedrijfadres_key = f.prs_bedrijfadres_key" // naar hetzelfde adres
+ " AND oudere.fac_srtnotificatie_key = f.fac_srtnotificatie_key" // over hetzelfde
+ " AND oudere.fac_notificatie_refkey = f.fac_notificatie_refkey" // over hetzelfde
+ " AND oudere.fac_notificatie_failcount > 0)" // oudere faler
+ " AND oudere.fac_notificatie_refkey = f.fac_notificatie_refkey)" // over hetzelfde
+ " AND f.prs_perslid_key_receiver = p.prs_perslid_key(+)"
+ " AND f.fac_srtnotificatie_key = fs.fac_srtnotificatie_key(+)"
@@ -104,7 +106,7 @@ function sendNotification(ref_key, pcode, params)
+ " , fac_notificatie_key";
Log2File(3, sql);
Log2File(3, sql);
if (S("puo_loglevel") > 1)
{
var oRs2 = Oracle.Execute("SELECT COUNT(*) FROM (" + sql + ")");
@@ -125,34 +127,33 @@ function sendNotification(ref_key, pcode, params)
while (true)
{
var oRs = Oracle.Execute(sql);
if (oRs.EOF)
if (oRs.EOF) // niets meer te doen
{
oRs.Close();
if (!delayed)
{
var sql2 = "SELECT MIN(fac_notificatie_notbefore) eerste"
var sql2 = "SELECT MIN(fac_notificatie_notbefore) eerstvolgende"
+ " FROM ({0})".format(sqlmain);
var oRs = Oracle.Execute(sql2)
if (oRs("eerste").Value != null)
if (oRs("eerstvolgende").Value != null)
{
delayed = new Date(oRs("eerste").Value);
delayed = new Date(oRs("eerstvolgende").Value);
}
oRs.Close();
}
/* TODO:
if S("puo_taskmaster") // Stoppen. De master start ons wel als het handig/ nodig
{
if (delayed)
{
puo_taskmaster.starttask(customerId, 'putorders', delayed);
}
else
{
puo_taskmaster.endtask(customerId, 'putorders');
}
break;
}
*/
if (S("tsk_master_schema")) // Stoppen. De master start ons wel als het handig/ nodig is
{
if (delayed)
{
//var sql2 = "BEGIN tsk.startputorders({0}); END;".format(delayed.toSQL(true, true));
var sql2 = "BEGIN tsk.starttask(taskcode => 'PUTORDERS', notbefore => {0}); END;".format(delayed.toSQL(true, true));
Log2File(3, sql2);
Oracle.Execute(sql2);
//puo_taskmaster.starttask(customerId, 'putorders', delayed);
}
// Taak was al wel verwijderd
break; // uit de loop
}
if (typeof WScript != 'undefined')
{
var now = new Date();
@@ -207,6 +208,13 @@ function sendNotification(ref_key, pcode, params)
notiPRSed += nn_success;
}
}
var sql2 = "DELETE fac_notificatie"
+ " WHERE fac_notificatie_status IN (0, 16)"
+ " AND fac_notificatie_systeemadres IS NULL"
+ " AND prs_bedrijfadres_key IS NULL"
+ " AND fac_notificatie_key = " + oRs("fac_notificatie_key").value;
Oracle.Execute(sql2);
}
Log2File(2, Fill(100, "=") + "\n\n");
@@ -959,6 +967,7 @@ function notificationPRS(rec, params)
nextdate.setMinutes(nextdate.getMinutes() + backofminutes);
var sql = "UPDATE fac_notificatie"
+ " SET fac_notificatie_failcount = " + failcount
+ " , fac_notificatie_faildatum = SYSDATE"
+ " , fac_notificatie_failmessage = " + safe.quoted_sql(SendOrderResult.errtext)
+ " , fac_notificatie_notbefore = " + nextdate.toSQL(true, true)
+ " WHERE fac_notificatie_key = " + rec("fac_notificatie_key").value

View File

@@ -77,6 +77,16 @@
/* global */ var custabspath = fso.GetAbsolutePathName("../");
var WshNetwork = new ActiveXObject("WScript.Network");
// Niet vroeger plaatsen in dit bestand. Settings laden heeft customerId nodig voor flexfilespath
if (S("tsk_master_schema"))
{
var stderr = fso.GetStandardStream (2);
stderr.WriteLine("Master schema is {0}. Output is probably redirected to a .lock file in master schema tempfolder.".format(S("tsk_master_schema")));
//stderr.WriteLine("Sleeping 5 seconds");
//WScript.Sleep(5*1000);
//stderr.WriteLine("Moving on...");
}
Log2File(0, "===========================================================");
Log2File(0, "PUTORDERS STARTED (" + toDateTimeString(applicatieRun) + ") " + WshNetwork.UserDomain + "\\" + WshNetwork.UserName);
Log2File(2, "puo_loglevel: " + S("puo_loglevel"));

View File

@@ -0,0 +1,115 @@
// ******************************************
// * $Id$
// *
// * tasker_loop()
// *
// * Start relevante taken
// *
// * Uses: scr="../wsf_shared.js"
// * scr="./puo_settings.js"
// * scr="./puo_shared.js
// *
// ******************************************
var fso = new ActiveXObject("Scripting.FileSystemObject");
function tasker_loop(params)
{
params = params || {};
Log2File(2, "** START tasker_loop (" + toDateTimeString(new Date()) + ")");
var sqltask
= "SELECT fac_task_key"
+ " , fac_cust_customerid"
+ " , fac_task_code"
+ " , fac_task_nextrun"
+ " FROM fac_task tt, fac_cust tsko"
+ " WHERE tt.fac_cust_key = tsko.fac_cust_key"
+ " AND fac_cust_enabled > 0"
+ " AND fac_task_nextrun <= SYSDATE"
+ " ORDER BY fac_task_nextrun"
+ " , fac_cust_customerid";
Log2File(3, sqltask);
var lastAction = new Date();
while (true)
{
var oRs = Oracle.Execute(sqltask);
if (oRs.EOF)
{
oRs.Close();
if (typeof WScript != 'undefined')
{
var now = new Date();
var since = Math.round((now.getTime() - lastAction.getTime()) / 1000);
var sincetxt = "" + Math.floor(since/3600) + ":" + padout(Math.floor(since/60 % 60)) + ':' + padout(since %60)
var txt = "Tasker has nothing to do since {0} ({1} ago). Sleeping 5 seconds.".format(toDateTimeString(lastAction), sincetxt);
WScript.Echo(txt);
}
WScript.Sleep(5000);
continue; // loopje in
}
var task_key = oRs("fac_task_key").value;
var owner_cust = oRs("fac_cust_customerid").value;
var task_code = oRs("fac_task_code").value;
var task_notbefore = new Date(oRs("fac_task_nextrun").value);
oRs.Close();
var lockfilename = custabspath + "/../../temp/" + customerId + "/" + owner_cust + "_" + task_code + ".lock";
//lockfilename = fso.GetAbsolutePathName(lockfilename) //
if (fso.FileExists(lockfilename)) // Already active?
{
try {
fso.DeleteFile(lockfilename);
}
catch (e)
{
Log2File(1, "Task seems busy in lockfile {0}\nNot starting task\n".format(lockfilename));
var sqlu = "UPDATE fac_task"
+ " SET fac_task_nextrun = fac_task_nextrun + 1/60/24" // Over 1 minuut weer testen
+ " WHERE fac_task_key = " + task_key;
Oracle.Execute(sqlu);
continue;
}
}
var sqlu = "UPDATE fac_task"
+ " SET fac_task_nextrun = NULL,"
+ " fac_task_lastrun = SYSDATE"
+ " WHERE fac_task_key = " + task_key;
Oracle.Execute(sqlu);
Log2File(1, "== Task " + task_key + "; "
+ owner_cust + " " + task_code + "; "
+ toDateTimeString(task_notbefore)
+ " (now: " + toDateTimeString(new Date()) + ")"
+ (params.userident ? " user: " + params.userident : "")
);
switch (task_code)
{
case "PUTORDERS":
var command = 'CMD /C "..\\..\\..\\utils\\putOrders\\putOrders.bat DEBUG"'; // Moet met backslashes voor CMD
var startin = custabspath + "/../" + owner_cust + "/tasks"
break;
default: ERROR_UNKNOWN_task_code;
}
//var tempfile = custabspath + "/../../temp/" + customerId + "/" + owner_cust + "_" + task_code + ".bat";
// overwogen om een tijdelijke batchfile met CD <<startin>> te maken
// maar Windows toont een security warning popup als je een nieuwe batchfile op W: gaat draaien
Log2File(2, "Starting " + command);
Log2File(2, " in " + startin);
var objShell = WScript.CreateObject("WScript.Shell");
var olddir = objShell.CurrentDirectory;
objShell.CurrentDirectory = startin;
var objResult = objShell.Run(command + ">" + lockfilename, S("puo_loglevel")>1?1:0, false); // 0=no window, async
objShell.CurrentDirectory = olddir;
lastAction = new Date();
}
}

View File

@@ -0,0 +1,73 @@
<![CDATA[
/*
$Id$
File: put_orders.wsf
Calling: cscript ..\..\..\utils\PutOrders\put_orders.wsf
Parameters:
Context: Scheduled task
Note: De code veronderstelt (nog) dat de current folder een cust/xxxx/tasks folder is
Concreter: ../Oracle.udl wordt gebruikt
*/
]]>
<job id="IncludeGenExport">
<script language="JScript" src="../wsf_shared.js"/>
<script language="JScript" src="../utils_settings.js"/>
<script language="JScript" src="../putorders/puo_shared.js"/>
<script language="JScript" src="../json2.js"/>
<script language="JScript" src="./gen_tasker.js"/>
<script language="JScript">
var applicatieRun = new Date();
try
{
var oAbout = new ActiveXObject("SLNKDWF.About");
WScript.Echo("SLNKDWF Version: " + oAbout.VersionString);
}
catch(e)
{
__Log("SLNKDWFx64.DLL is not properly installed.\n{0}".format(e.description));
WScript.Quit(1);
}
var Oracle = Connect2Oracle('gen_tasker.wsf');
var sql = "SELECT fac_version_cust FROM fac_version";
var oRs = Oracle.Execute(sql);
var customerId = oRs(0).Value;
oRs.Close();
__Log("CustomerId: " + customerId);
var fso = new ActiveXObject("Scripting.FileSystemObject");
// We zijn altijd gescheduled vanuit cust/XXXX/Tasks
/* global */ var custabspath = fso.GetAbsolutePathName("../");
var WshNetwork = new ActiveXObject("WScript.Network");
Log2File(0, "===========================================================");
Log2File(0, "PUTORDERS STARTED (" + toDateTimeString(applicatieRun) + ") " + WshNetwork.UserDomain + "\\" + WshNetwork.UserName);
Log2File(2, "puo_loglevel: " + S("puo_loglevel"));
try
{
tasker_loop();
var sql = "UPDATE fac_version"
+ " SET fac_version_tasker_date = SYSDATE";
Oracle.Execute(sql);
}
catch(e)
{
Log2File(0, "Uncaught error in gen_tasker.wsf: " + e.description, "E");
}
var endDate = new Date();
var duration = Math.round((endDate - applicatieRun) / 100) / 10;
Log2File(0, "PUTORDERS FINISHED ({0}, duration {1}s)".format(toDateTimeString(endDate), duration));
Oracle.Close();
</script>
</job>

View File

@@ -166,9 +166,16 @@ function tryOverrule(path)
},
DEFAULT: function (naam, type, waarde)
{
settings[naam]= {v: waarde, t: type};
__Log(" Defaulting " + (naam + " ").substr(0, 22) + " to: " + waarde);
return;
if (naam in settings)
{
__Log(" Default " + (naam + " ").substr(0, 22) + " has already value " + settings[naam].v);
}
else
{
settings[naam]= {v: waarde, t: type};
__Log(" Defaulting " + (naam + " ").substr(0, 22) + " to: " + waarde);
}
return;
},
LCL: function (naam, waarde)
{