This commit is contained in:
2022-07-18 11:48:07 -04:00
parent 7f4dbca484
commit da16ee8f06
+62 -4
View File
@@ -23,36 +23,69 @@ long SignUpStats(CVars in, CVars &out);
long PastDueWarings(CVars in, CVars &out);
long PastDueOffersRefund(CVars in, CVars &out);
long CronTracker(CVars in, CVars &out);
/*
CREATE TABLE cron_jobs (
id SERIAL,
job_type VARCHAR(50) UNIQUE NOT NULL,
description VARCHAR(55) NOT NULL,
added timestamp without time zone DEFAULT now(),
updated timestamp without time zone DEFAULT now(),
active INT DEFAULT 0
);
ALTER TABLE ONLY cron_jobs
ADD CONSTRAINT cron_jobs_id_key UNIQUE (id);
*/
long sitecrons_calls(CVars in, CVars &out) {
logfmt(logINFO, "sitecrons_calls()");
//out["result"] = "YES I GET TO BACK END";
long call_action = REQ_LONG(in, "call_action", 0, -1);
CVars x;
CVars ct,co;
long ret = 0;
const char * loc = getenv("REMOTE_ADDR");
logfmt(logINFO, "sitecrons_calls() action=%lu",call_action);
switch (call_action) {
case WRB_CRONJOB_JOBDUE_REMINDER:
ct["job_type"]="WRB_CRONJOB_JOBDUE_REMINDER"; ct["job_type"].set_valid( true );
ct["description"]="This is to organize and send job due date remider to client"; ct["description"].set_valid( true );
CronTracker(ct, co);
return DeadlineLineApprachClient(in, out);
break;
case WRB_CRONJOB_JOBDUE_PAYMENTS:
ct["job_type"]="WRB_CRONJOB_JOBDUE_PAYMENTS"; ct["job_type"].set_valid( true );
ct["description"]="This is to organize jonb compleyted remider to owner of task"; ct["description"].set_valid( true );
return PaymentPending(in, out);
break;
case WRB_CRONJOB_SIGNUP_ALERT:
ct["job_type"]="WRB_CRONJOB_SIGNUP_ALERT"; ct["job_type"].set_valid( true );
ct["description"]="General Signup job stats "; ct["description"].set_valid( true );
CronTracker(ct, co);
return SignUpStats(in, out);
break;
case WRB_CRONJOB_PASTDUE_ALERT:
ct["job_type"]="WRB_CRONJOB_PASTDUE_ALERT"; ct["job_type"].set_valid( true );
ct["description"]="This is to organize and send job due date remider to owner of task"; ct["description"].set_valid( true );
CronTracker(ct, co);
return PastDueWarings(in, out);
break;
case WRB_CRONJOB_OFFER_REFUND_ALERT:
ct["job_type"]="WRB_CRONJOB_OFFER_REFUND_ALERT"; ct["job_type"].set_valid( true );
ct["description"]="Offer expired , need to cancel and return deposit for the offer"; ct["description"].set_valid( true );
CronTracker(ct, co);
return PastDueOffersRefund(in, out);
break;
case WRB_CRONJOB_PENDOFFER_ALERT:
ct["job_type"]="WRB_CRONJOB_PENDOFFER_ALERT"; ct["job_type"].set_valid( true );
ct["description"]="Offer is pending remind the client to attend to it before it expires "; ct["description"].set_valid( true );
CronTracker(ct, co);
return OfferPending(in, out);
break;
@@ -62,6 +95,31 @@ long sitecrons_calls(CVars in, CVars &out) {
return ret;
}
long CronTracker(CVars in, CVars &out){
long ret = PHP_API_BAD_PARAM;
const PGresult *res;
try {
REQ_STRING(in, "job_type", 2, 149, "(.*)");
REQ_STRING(in, "description", 2, 149, "(.*)");
if ( load_db_record(out, "SELECT id AS cron_id FROM cron_jobs WHERE job_type ='%s' ", in["job_type"].c_str())> 0){
res = pgsql_query("UPDATE cron_jobs SET updated=now() WHERE id = %lu", out["cron_id"].Long());
}
else{
CVars xx;
xx["job_type"] = in["job_type"];
xx["job_type"].set_valid(true);
xx["description"] = in["description"];
xx["description"].set_valid(true);
long cron_id = insert_db_record(DBS_VALID, "cron_jobs", "cron_jobs_id_seq", xx);
}
} catch (bad_parameter) {
out["action_status"] = "Invalid CronTracker Action";
}
return ret;
}
long ReviewReminder(CVars in, CVars &out) {
@@ -70,14 +128,14 @@ long ReviewReminder(CVars in, CVars &out) {
long OfferPending(CVars in, CVars &out) {
logfmt(logINFO, "ENTER OfferPending()");
long limit = in["one_limit"].Long();
const PGresult *res = pgsql_query("SELECT jo.id AS offer_id,jo.added,j.title,jo.expire,jo.email, jo.client_id, "
"jo.job_id,jo.reminder_count,jo.reminder_date "
"FROM members_jobs_offer jo "
"LEFT JOIN members_jobs j ON j.id = jo.job_id "
"WHERE now() > jo.added +'6 hrs' "
"AND jo.expire > now() AND jo.status = 1 AND jo.public_view =0 "
"AND jo.reminder_count =0 AND jo.reminder_date IS NULL LIMIT 1 ");
"AND jo.reminder_count =0 AND jo.reminder_date IS NULL LIMIT %lu ",limit);
if (res != NULL && pgsql_num_rows(res) > 0) {
for (int i = 0, n = pgsql_num_rows(res); i < n; i++) {
@@ -151,7 +209,7 @@ long PastDueWarings(CVars in, CVars &out) {
contract_id = rec["contract_id"].Long();
cron_email(WRB_CRONJOB_PASTDUE_ALERT, rec, out); // send the cron email
}
pgsql_exec("UPDATE members_jobs_contract SET auto_remind=auto_remind + 1 "\
pgsql_exec("UPDATE members_jobs_contract SET auto_remind=auto_remind + 1,due_remind=now() "\
"WHERE member_id=%lu AND id = %lu ", rec["member_id"].Long(),rec["contract_id"].Long());
}