]> git.ipfire.org Git - thirdparty/HylaFAX.git/commitdiff
Refactor faxQueueApp to pull job send checking to isJobSendOK()
authorAidan Van Dyk <aidan@ifax.com>
Fri, 4 May 2007 17:20:08 +0000 (17:20 +0000)
committerAidan Van Dyk <aidan@ifax.com>
Fri, 4 May 2007 17:20:08 +0000 (17:20 +0000)
Pull out the checks to see if a job is actually good to send now.  These
used to all be inside the runSchedule() loop.  This brings them to their
own separate function, simplifying the runScheduler() loop, and possibly
allowing the checks to be used from other places.

faxd/faxQueueApp.c++
faxd/faxQueueApp.h

index 9410a793cd597f46a15edd3b9f6d007297320f51..2677da79f563768fa63d9827f8e4b3059a3f94e7 100644 (file)
@@ -2206,6 +2206,70 @@ faxQueueApp::runJob(Job& job)
     }
 }
 
+/*
+ * Check if a job is runnable.  If it is, it will return true,
+ * and the job/req are left for the caller to deal with.  If the
+ * job is not runnable, it returns false, and the job and req will
+ * have been dealt with appropriately (put on another list, deleted,etc
+ */
+bool
+faxQueueApp::isJobSendOK (Job& job, FaxRequest* req)
+{
+    /*
+     * Constrain the maximum number of times the phone
+     * will be dialed and/or the number of attempts that
+     * will be made (and reject jobs accordingly).
+     */
+    u_short maxdials = fxmin((u_short) job.getJCI().getMaxDials(),req->maxdials);
+    if (req->totdials >= maxdials) {
+       rejectJob(job, *req, fxStr::format(
+           "REJECT: Too many attempts to dial: %u, max %u",
+           req->totdials, maxdials));
+       deleteRequest(job, req, Job::rejected, true);
+       return false;
+    }
+    u_short maxtries = fxmin((u_short) job.getJCI().getMaxTries(),req->maxtries);
+    if (req->tottries >= maxtries) {
+       rejectJob(job, *req, fxStr::format(
+           "REJECT: Too many attempts to transmit: %u, max %u",
+           req->tottries, maxtries));
+       deleteRequest(job, req, Job::rejected, true);
+       return false;
+    }
+    // NB: repeat this check so changes in max pages are applied
+    u_int maxpages = job.getJCI().getMaxSendPages();
+    if (req->totpages > maxpages) {
+       rejectJob(job, *req, fxStr::format(
+           "REJECT: Too many pages in submission: %u, max %u",
+           req->totpages, maxpages));
+       deleteRequest(job, req, Job::rejected, true);
+       return false;
+    }
+    if (job.getJCI().getRejectNotice() != "") {
+       /*
+        * Calls to this destination are being rejected for
+        * a specified reason that we return to the sender.
+        */
+       rejectJob(job, *req, "REJECT: " | job.getJCI().getRejectNotice());
+       deleteRequest(job, req, Job::rejected, true);
+       return false;
+    }
+    time_t now = Sys::now();
+    time_t tts;
+    if ((tts = job.getJCI().nextTimeToSend(now)) != now) {
+       /*
+        * This job may not be started now because of time-of-day
+        * restrictions.  Reschedule it for the next possible time.
+        */
+       job.remove();                   // remove from run queue
+       delayJob(job, *req, "Delayed by time-of-day restrictions", tts);
+       delete req;
+       return false;
+    }
+
+    return true;
+}
+
 /*
  * Scan the list of jobs and process those that are ready
  * to go.  Note that the scheduler should only ever be
@@ -2272,51 +2336,18 @@ faxQueueApp::runScheduler()
                    setDead(job);
                    continue;
                }
+
                /*
-                * Do per-destination processing and checking.
+                * Do job limits and checking
                 */
-               DestInfo& di = destJobs[job.dest];
+               if (! isJobSendOK(job, req) )
+                   continue;
+
                /*
-                * Constrain the maximum number of times the phone
-                * will be dialed and/or the number of attempts that
-                * will be made (and reject jobs accordingly).
+                * Do per-destination processing and checking.
                 */
-               u_short maxdials = fxmin((u_short) job.getJCI().getMaxDials(),req->maxdials);
-               if (req->totdials >= maxdials) {
-                   rejectJob(job, *req, fxStr::format(
-                       "REJECT: Too many attempts to dial: %u, max %u",
-                       req->totdials, maxdials));
-                   deleteRequest(job, req, Job::rejected, true);
-                   continue;
-               }
-               u_short maxtries = fxmin((u_short) job.getJCI().getMaxTries(),req->maxtries);
-               if (req->tottries >= maxtries) {
-                   rejectJob(job, *req, fxStr::format(
-                       "REJECT: Too many attempts to transmit: %u, max %u",
-                       req->tottries, maxtries));
-                   deleteRequest(job, req, Job::rejected, true);
-                   continue;
-               }
-               // NB: repeat this check so changes in max pages are applied
-               u_int maxpages = job.getJCI().getMaxSendPages();
-               if (req->totpages > maxpages) {
-                   rejectJob(job, *req, fxStr::format(
-                       "REJECT: Too many pages in submission: %u, max %u",
-                       req->totpages, maxpages));
-                   deleteRequest(job, req, Job::rejected, true);
-                   continue;
-               }
-               if (job.getJCI().getRejectNotice() != "") {
-                   /*
-                    * Calls to this destination are being rejected for
-                    * a specified reason that we return to the sender.
-                    */
-                   rejectJob(job, *req, "REJECT: " | job.getJCI().getRejectNotice());
-                   deleteRequest(job, req, Job::rejected, true);
-                   continue;
-               }
-               time_t now = Sys::now();
-               time_t tts;
+               DestInfo& di = destJobs[job.dest];
+
                if (!di.isActive(job) && !isOKToCall(di, job.getJCI(), 1)) {
                    /*
                     * This job would exceed the max number of concurrent
@@ -2329,14 +2360,6 @@ faxQueueApp::runScheduler()
                    job.remove();                       // remove from run queue
                    di.block(job);                      // place at tail of di queue
                    delete req;
-               } else if ((tts = job.getJCI().nextTimeToSend(now)) != now) {
-                   /*
-                    * This job may not be started now because of time-of-day
-                    * restrictions.  Reschedule it for the next possible time.
-                    */
-                   job.remove();                       // remove from run queue
-                   delayJob(job, *req, "Delayed by time-of-day restrictions", tts);
-                   delete req;
                } else if (assignModem(job)) {
                    job.remove();                       // remove from run queue
                    /*
index bd605707972041ca45898324582c2baf8adf3857..14258a463ac554ecc7132f24fa4b033a2ec8b067 100644 (file)
@@ -205,6 +205,7 @@ private:
                    bool force, const char* duration = "");
     void       notifySender(Job&, JobStatus, const char* = "");
 // job management interfaces
+    bool       isJobSendOK(Job& job, FaxRequest* req);
     void       processJob(Job& job);
     void       processJob(Job&, FaxRequest* req, DestInfo& di);
     void       sendJobStart(Job&, FaxRequest*);