User Tools

Site Tools


en:wiki:2.-desarrollo-app:2.3.-codigo:c.-eventos:7.-maintenance:start



MAINTENANCE Node


To define maintenances in an application we must add the <maintenance> node to a collection.

It will depend on the relation of the action that is going to be taken with the collection, that is, if we are going to perform a very generic action that does not depend on any collection, then we can define it in the collection that we want, on the contrary, if the action, for instance, is an script and in it we access some of the particularities of the collection, in that case, we must define it in that collection.

The maintenances always are added as a tab at the end of the existing ones (in Windows Mobile).

To execute background maintenances that happen every so often, independently of the collection where we are in, they are put in the “Empresas” collection.

It is also remembered that it is MANDATORY to have a company and an user associated to that company in the gen-empresa tables and gen-usuarios respectively.

Structure:


<coll name="empresas" ....>
	<maintenance>
		<action name="Documentos" type="runscript" period="D" frecuency="1" showintab="false" executealways=”true”>
			<script language="VBScript">
				......
				......
			</script>	
		</action>
	</maintenance>
</coll>

Next, the attributes of the action specific for the maintenance node are explained:

ATTRIBUTE DESCRIPTION
period=“ S / X / H / D / M / Y ” It indicates the time frame taken to make the calculation. Seconds, Minutes, Hours, Days, Months and Years respectively.
frecuency=“Value” It is a number that indicates the timescales that have to elapse for maintenance to occur.
executealways=“true/false” The maintenance having that property is executed to true, when it is its turn, although we are inside of any collection.
Showintab=”true/false” It indicates if the maintenance must appear in the maintenance tab or it must not. Value by default “true”

In Windows Mobile a “maintenances” tab is shown by default with the actions thar are executed.

If we want to hide the “maintenances” tab by hiding too the replica console, we have to put Showintab=”false” to a maintenance level.

NEW WAY TO PERFORM MAINTENANCES


ATTENTION! in the new frameworks (Android, Iphone), a possible loss of information has been detected in the replica.

Previously in Windows Mobile for example, when it was in the editing window, the maintenance was not executed so as not to penalize the performance of the application. Now with the new frameworks with multicore, multithread and other hardware, this is no longer a problem and several scripts can run simultaneously.

Here is where the problem has been found… When we did execute a maintenance, at the beginning it was put AppData.IsReplicating=false“, causing that the operations defined below don´t enter in replica.
Now, as several scripts can be executed at the same time, if a maintenance jumps for example at the moment we are doing some operations pressing a button on an application screen, the IsReplicating disables the replica NOT ONLY FOR THE MAINTENANCES, so that the operations that could have been done with the button have not been replicated either.

To avoid this, a new way of working has been defined when we do not want to replicate information, by deleting the use of IsReplicating.

1.- We define a Collection that makes us connect to the DB to execute the SQL that we do not want to enter in a replica.

<coll name="ForMaintenance" title="ForMaintenance" objname="ForMaintenance" updateobj="ForMaintenance" progid="ASData.CASBasicDataObj" 
	sql="SELECT t1.*
	FROM ##PREF##ForMaintenance t1" connection="mtto">
	<connection name="mtto" connstring="bd/gestion.db" />
	<group name="General" id="1" />
</coll>

2.- Define maintenances.

This code would be for VBScript:

<maintenance>
	<action name="Borrado datos" type="runscript" period="D" frecuency="1">											
		<script language="VBScript">
			On error resume next
			' Borramos las lineas de Documentos con ID Null
			appdata.GetCollection("ForMaintenance").ExecuteSqlString "DELETE FROM Gen_detdocumento WHERE IDDOCUMENTO IS NULL"
			......
			......
		</script>
	</action>									
</maintenance>


This code would be for JavaScript:

<maintenance>
	<action name="Borrado datos" type="runscript" period="D" frecuency="1">											
		<script language="javascript">
			//Borramos las lineas de Documentos con ID Null
			appData.getCollection("ForMaintenance").executeSqlString("DELETE FROM Gen_detdocumento WHERE IDDOCUMENTO IS NULL");
			......
			......
		</script>
	</action>									
</maintenance>

OLD MAINTENANCES


<maintenance>
	<!-- This action forces the replica in case there is any data pending of sending. PocketPC ONLY -->
	<action name="Proxima Comunicacion" type="replica" frecuency="10" period="X" synchronize="true"/>
 
	<!-- Daily, a refresh in the data tables will be made. -->
	<action name="Borrado datos" type="runscript" period="D" frecuency="1">											
		<script language="VBScript">
			On error resume next
			appdata.IsReplicating = false 
			' Lineas de Documentos con ID Null
			appdata.executeSQL "DELETE FROM Gen_detdocumento WHERE IDDOCUMENTO IS NULL"            
			' Lineas y Cabeceras de Documentos anteriores a 15 dias
			appdata.executeSQL "DELETE FROM Gen_documentos WHERE DATEDIFF(DAY,FECHA,GETDATE())&gt;15 and ROWID not in (select ROWID from master_replica_queue)"
			appdata.executeSQL "DELETE FROM Gen_detdocumento WHERE IDDOCUMENTO IN(SELECT ID FROM Gen_Documentos WHERE DATEDIFF(DAY,FECHA,GETDATE())&gt;15) and ROWID not in (select ROWID from master_replica_queue)"
			appdata.executeSQL "DELETE from gen_ofertas where DATEDIFF(DAY,FECHAFIN,GETDATE())&gt;1"
			appdata.executeSQL "DELETE from gen_detoferta where IDOFERTA not in (select id from gen_ofertas)"
			appdata.IsReplicating = true 
		</script>
	</action>									
</maintenance>

The maintenance, also, can be used at the time to create our own system of warnings (replica notifications), as it can be seen in here.

en/wiki/2.-desarrollo-app/2.3.-codigo/c.-eventos/7.-maintenance/start.txt · Last modified: 2017/12/01 09:46 by patricia