Files
Facilitor/APPL/API/api_marknotisent.asp
Jos Groot Lipman 1e2b050e96 Merge 2023.1 Gold A patches
svn path=/Website/trunk/; revision=59559
2023-03-13 11:41:12 +00:00

114 lines
4.6 KiB
Plaintext

<%@ language = "JavaScript" %>
<% /*
$Revision$
$Id$
File: api_marknotisent.asp
Description: API om custom notificatie queue te manipuleren
Parameters: noti_key een fac_notificatie_key
resultcode als die >= 0 is wordt het bitje 64 van de notificatie gereset
track_text wordt getrackt bij de xmlnode van de notificatie
Context: Wordt door de MARX adapter gebruikt
Notes: Voor notificaties waar bitje 64 van fac_notificatie_status is gezet
Er is een database procedure fac.marknotiassent die min of meer hetzelfde doet
maar (nog) ongebruikt is.
*/
JSON_Result = true;
THIS_FILE = "appl/api/api_marknotisent.asp";
%>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../api/api.inc" -->
<%
// TODO: Welke autorisatie is logisch?
// APIKEY is van een leverancier waarvan de opdracht bijgewerkt gaat worden in AX
/// Die leverancier moet wijzigrechten op de opdracht (/factuur/melding/contract/xxx) hebben?
// var authparams = user.checkAutorisation("WEB_FACHML");
var API = new API_func();
var result = { success: true };
var noti_key = getQParamInt("noti_key");
var resultcode = getQParamInt("resultcode");
var track_text = getQParam("track_text", "");
var sql = "SELECT fac_notificatie_refkey"
+ " , fac_notificatie_status"
+ " , fac_notificatie_datum"
+ " , fac_notificatie_notbefore"
+ " , fac_notificatie_failcount"
+ " , fac_srtnotificatie_xmlnode"
+ " FROM fac_notificatie fs"
+ " , fac_srtnotificatie fsn"
+ " WHERE fs.fac_srtnotificatie_key = fsn.fac_srtnotificatie_key"
+ " AND fs.fac_notificatie_key = " + noti_key;
var oRs = Oracle.Execute(sql);
if (oRs.EOF)
API.error("Notification key {0} not found".format(noti_key));
var ref_key = oRs("fac_notificatie_refkey").Value;
var noti_status = oRs("fac_notificatie_status").Value;
var xmlnode = oRs("fac_srtnotificatie_xmlnode").Value;
var noti_datum = new Date(oRs("fac_notificatie_datum").Value);
var notbefore = new Date(oRs("fac_notificatie_notbefore").Value);
var failcount = oRs("fac_notificatie_failcount").Value;
oRs.Close();
if ((noti_status & 64) == 0)
API.error("Notification key {0} status {1} does not have bit 64 set".format(noti_key, noti_status));
if (track_text)
{
var trackcode = { "opdracht": "ORDTRK",
"melding": "MLDTRK",
"bestelopdr": "BESTRK",
"contract": "CNTTRK",
"factuur": "FINTRK"
}[xmlnode];
if (!trackcode)
API.error("Tracking for xmlnode {0} unknown".format(xmlnode));
shared.trackaction (trackcode, ref_key, track_text);
}
if (resultcode >= 0)
{
var sql = "UPDATE fac_notificatie"
+ " SET fac_notificatie_status = BITAND (fac_notificatie_status, 255 - 64)"
+ " WHERE fac_notificatie_key = " + noti_key;
Oracle.Execute(sql);
}
else
{
failcount ++;
// Interval tussen pogingen steeds 10 minuten langer, max 120 minuten
//var backofminutes = Math.min(S("puo_faildelaymax"), failcount * S("puo_faildelayincrement"));
// Interval tussen pogingen steeds 30 minuten langer, max 60*24 minuten
var backofminutes = Math.min(60*24, failcount * 30);
var nextdate = new Date();
nextdate.setMinutes(nextdate.getMinutes() + backofminutes);
var sql = "UPDATE fac_notificatie"
+ " SET fac_notificatie_failcount = " + failcount
+ " , fac_notificatie_notbefore = " + nextdate.toSQL(true)
+ " WHERE fac_notificatie_key = " + noti_key;
Oracle.Execute(sql);
// Let op dat er latere notificaties over dezelfde xmlnode kunnen zijn of kunnen komen
// Als je wilt dat ze nooit out-of-order worden verwerkt moet de custom-queue
// processor zelf zo slim zijn om ook te stoppen met deze opdracht zodra hij
// *een* notbefore in de toekomst tegenkomt.
// Als de aanroeper nog een cursor op fac_v_notifyqueue open heeft staan ziet
// die cursor bovenstaande wijziging nog niet!
result.failcount = failcount;
result.nextdate = nextdate;
__DoLog("Notification key {0} xmlnode {1} refkey {2} failed {3} time(s) since {4} , delaying until {5}".format(noti_key, xmlnode, ref_key,
failcount, toDateTimeString(noti_datum), toDateTimeString(nextdate)));
}
__Log(result);
Response.Write(JSON.stringify(result));
%>
<% ASPPAGE_END(); %>