Once_A-Day Online Task Automation 1) Save this file as "once_a_day.mv" on your local computer. 2) Setup the user configuration variables below then save this file online in your MivaDocumentRoot or a subdirectory thereof. Run this file and then select "Docs" for help using this software. Requires Miva version 3.xxx Brian R.Bullock brian@wwwebweaver.com http://wwwebweaver.com/func_junc/ Released to the public domain June 24, 2001 ============================================ Table Of Contents for NoteTab v4.0+ Control "doubleclick" on function name: [::_____Docs_____] [::_____Run_Tasks_____] [::_____Create_db_____] [::_____Import_db_____] [::_____Export_db_____] [::_____Reindex_db_____] [::_____Pack_db_____] [::_____Add_Task_____] [::_____Edit_Task_____] [::_____Delete_Task_____] [::_____Undelete_Task_____] [::_____Open_All_____] [::_____Lock_All_____] [::_____Save_Rec_____] [::_____Rec2Ram_____] [::_____Search_Form_____] [::_____Choose_Rec_____] [::_____List_View_____] [::_____Table_View_____] [::_____Display_rec_____] [::_____Build_Filter_____] [::_____Add_Bool_____] [::_____Phrase_Filter_____] [::_____Logon_____] [::_____If_Logged_____] [::_____Validate_____] [::_____Get_Password_____] [::_____IP2Hex_____] [::_____Build_Checksum_____] [::_____find_token_____] [::_____Online_____] [::_____Offline_____] ######################################################### WARNING: CHANGE THE PASSWORD BEFORE STORING ONLINE. ######################################################### ======================================================= Use 8 or more characters in your new password. Double quotes and curly brackets are the only characters not allowed in 'Admin_Password'. ======================================================= Change the value of 'Allow_Multi_User' to 1 if you want to disable the built-in password protection thereby allowing multi-user access to this script. Note: Store this script in a password protected directory if you allow multi-user access otherwise it will be completely unprotected. ======================================================= 'Max_Time_Inactive' is the maximum time, in seconds, that may pass between script accesses before a new logon is required (900 sec.= 15 minutes). ======================================================= 'gfilters2display' is the number of "filtered field" input boxes to display in the search form. ======================================================= gcharacters2display' is the number of MEMO field characters to display in the "Choose Record" form. ######################################################### END OF USER CONFIGURATION VARIABLES ######################################################### Once_A_Day Online Task Automaton
Once_A_Day Online Task Automaton
Create_db Import_db Export_db Reindex_db Pack_db
Add_Task Edit_Task Delete_Task Undelete_Task Docs
_____Docs_____

What Does Once_A_Day do?
Why only once a day?
How does it work?
How do I use it on my site?

What Does Once_A_Day do?

This software provides the tools required to automatically run any existing Miva script, or function within any existing Miva script, once each day. Think of it as a limited CRON subsitute for people without CRON.

It has two primary limitations. First, you shouldn't give it tasks that take more than about 30 seconds to process and second, it only processes each task one time per day.

TOP

 

Why only once a day?

When a host doesn't provide CRON, the two reasons usually given are "it would be abused by newbies running lots of tasks real close together thereby degrading server response" and "CRON is too difficult to support". Although I'm also concerned about server hogs (NIMBY :), I feel the ability to automate a task is too important of a tool to lose because some newbies may abuse it.

I've addressed the hosting concerns by designing this software to only run each task once per day and to run all tasks as close to midnight server time as possible. Since this is open source software, any reasonably competent Miva programmer can figure out how to change the timer but I think anyone at that skill level will also have the knowledge and desire to use this software reponsibly.

And since this is not software supplied by the host, they don't have to support it. Hopefully I've done a good enough job that you won't even need to contact me :).

TOP

 

How does it work?

CRON runs in the background so your visitors don't know its running. Unfortunately Miva can not run in the background so additional Miva processing shows up as an increased delay in the page being served to the visitor.

This software works by attaching a task onto one of your visitor's requests for a page. The visitor will only be used once, to process one task, then their IP address is granted an one hour exemption (by which time they'll probably be long gone and someone else will be using that IP address). Another visitor will be chosen if another task needs to be processed. To your visitor it will seem like one of the pages from your site took longer to load than the others but since it only happened once they'll probably chalk it up to a temporary internet glitch.

Using this method requires you to practise restraint. If the tasks you run take too long to process then your visitor may think something is wrong and reload the page or, in the worst case, the combined time to process the task and serve the page will take longer than your global timeout and your visitor will get an error message.

Another implicatation of using this method is that the more visitors to your site the faster your daily tasks will be completed. For example if you only have ten visitors per day to your site and the first visitor accesses your site at 10 AM then the first task won't be completed until 10 AM and you can only process a maximum of ten tasks per day (one per visitor).

TOP

 

How do I use it on my site?

Installing this software
  • Load this file into your favorite text editor and change the USER CONFIGURATION VARIABLES (starting on line 63) to suit your site, then save it.
  • Use FTP to upload this file to your MivaDocumentRoot or a subdirectory of your MivaDocumentRoot.
  • Run the online copy of this file and select the "Create_db" option.

Setting up your site
Add one of the two chunks of code below to each Miva script used on your site:

<MvDO FILE = "/path/to/once_a_day.mv"
  NAME = ""
  VALUE = "{Run_Tasks()}">

or

<MvDO FILE = "/path/to/once_a_day.mv"
  NAME = "g.MyVarName"
  VALUE = "{Run_Tasks()}">

Use the first chunk of code if none of your tasks MvFUNCRETURN data.
Use the second chunk of code if any of your tasks MvFUNCRETURN data.
Note: if you use the second chunk of code then all of your Miva scripts will have to be able to process any data returned by all Once_A_Day tasks.

The simplest way to use this software is to add the first chunk of code to each of the Miva scripts on your site and design all of your tasks to complete all of the processing required for that task. But sometimes that uses too much time and you must split your tasks into subtasks. The second chunk of code may be useful if you need to split up your tasks.

You can also use server side includes to run Once_A_Day by writing a "stand-alone" script (named "includes.mv" for example) that only contains the first chunk of code above, then adding this line in your ".shtml" documents:
<!--#include virtual="/cgi-bin/miva?path/to/includes.mv" -->
Note: Your SSI server requirements may differ. Contact your tech support if that code doesn't work on your server.

You can place the code any place in your script that you want. For example if it is at the very top of your script then it will run every time that script is accessed... but if the script displays multiple pages then adding the code to the very top will waste processing time because Once_A_Day will have to check the IP address each time the visitor goes to the next page. In that situation its more efficient to place the chunk of code in a area of your script that is only processed once for each visitor (ie: the introduction page for the script).

Creating tasks

A Once_A_Day task can be any script or function stored in a script. The miva code for the task is not stored in the task database... only the path/filename of the task is stored in the database.

Write the Miva code for your task and upload it to your server. For security, you can write your tasks as functions in a library then put a MvEXIT as the first line in the library. That will ensure your tasks can only be run by Once_A_Day or another script on your server.

After uploading your task, whether stand-alone or function library, use the "Add_Task" option on your online version of this file to add the new task's info to the database.

And thats it! Your first visitor after midnight server time to access one of the Miva scripts that you added the code to will be used to process the first of your daily tasks, the second visitor will be used for the second task, and so on.

TOP

Brian R. Bullock
brian@wwwebweaver.com
http://wwwebweaver.com/func_junc/
Released to the public domain June 24, 2001

Need a free Miva editor? Check out:

      MvTools      
MvTools is a Miva and HTML development environment that's perfect for all Miva programmers, from beginners to experienced professionals. Its robust code editor includes a full range of professional-level editing features, and supports multiple open files. Rapid and accurate coding is facilitated by a push-button CodeMaker, which generates all standard Miva tags and functions, as well as all standard HTML tags. Scripts can be tested seamlessly using an efficient IE 4.x browser control that is fully integrated with Miva Mia. The program also provides dedicated editors for Miva's site variables and the Windows Hosts file, along with one-click access to the Miva Reference.

System requirements: Miva Mia and Win9x with IE 4.0 or greater.

Download Wish List Email List
_____Create_db_____ _____Import_db_____ _____Export_db_____ _____Reindex_db_____ _____Pack_db_____ _____Add_Task_____ _____Edit_Task_____ _____Delete_Task_____ _____Undelete_Task_____ _____Open_All_____ _____Save_Rec_____ _____Rec2Ram_____ The PARAMETER precno must be a valid db record number. _____Search_Form_____ _____Choose_Rec_____ _____List_View_____ _____Table_View_____ _____Display_rec_____ _____Build_Filter_____ _____Add_Bool_____ _____Phrase_Filter_____ ________Logon________ ________If_Logged________ ________Validate________ ________Get_Password________
Your Password was incorrect. Enter your password

________IP2Hex________ _______Build_Checksum________ Modified Smartronics Communications - SmartChek Algorithm _____find_token_____ _____Online_____ _____Offline_____