Cron Job
    • 1 Minute to read
    • Dark
      Light

    Cron Job

    • Dark
      Light

    Article summary

    We recommend using a cron job to send the logfile requests to the Mapp tracking server every few minutes and empty your file to keep it at a manageable size. You have two possibilities:

    Custom Cron Job File

    This option requires you to write your own cron job file and use our MappIntelligenceCronjob class.

    Integration

    Maven

    <dependency>
        <groupId>com.mapp.intelligence.tracking</groupId>
        <artifactId>cronjob</artifactId>
        <version>0.1.5</version>
    </dependency>

    Gradle

    compile group: 'com.mapp.intelligence.tracking', name: 'cronjob', version: '0.1.5'

    Methods

    constructor

    For a complete configuration of the Mapp Intelligence Cronjob please check Configuration.

    /**
     * @param config Mapp Intelligence config
     * @throws MappIntelligenceException Mapp Intelligence configuration exception
     */
    MappIntelligenceCronjob cronjob = new MappIntelligenceCronjob(MappIntelligenceConfig config);

    run

    Send the logfile requests to the Mapp tracking server and delete your logfiles to keep it at a mangeable size. Returns the following results:

    • 0: All data was sent successfully.

    • 1: An error has occurred.

    /**
     * @return Status
     */
    cronjob.run();
    Example
    package demo.cronjob;
    
    import com.mapp.intelligence.tracking.MappIntelligenceConfig;
    import com.mapp.intelligence.tracking.MappIntelligenceCronjob;
    
    public class MappIntelligenceCronjobCommandLine {
    	public static void main(String[] args) {
            int status = 1;
            try {
    			MappIntelligenceConfig mappIntelligenceConfig = new MappIntelligenceConfig();
    			mappIntelligenceConfig.setTrackId("111111111111111");
    			mappIntelligenceConfig.setTrackDomain("analytics01.wt-eu02.net");
    			mappIntelligenceConfig.setFilePath("/path/to/your/log/file/");
    			mappIntelligenceConfig.setFilePrefix("MappIntelligenceData");
    			
                MappIntelligenceCronjob c = new MappIntelligenceCronjob(mappIntelligenceConfig);
                status = c.run();
            } catch (Exception e) {
                // do nothing
            }
    
            System.exit(status);
        }
    }

    Predefined Cron Job Script

    This option allows you to use our predefined mapp-intelligence-java-cronjob.jar file, which is included in our repository

    Short notation

    Long notation

    Description

    -i

    --trackId

    Enter your Mapp Intelligence track ID provided by Mapp.

    -d

    --trackDomain

    Enter your Mapp Intelligence tracking URL.

    -f

    --filePath

    Enter the path to your request logging file.

    -p

    --filePrefix

    Enter the prefix for your request logging files.


    -c

    --config

    Enter the path to your configuration file (*.properties or *.xml).



    --debug

    Activates the debug mode. The debug mode sends messages to the command line.


    --help

    Display the help (this text) and exit.


    --version

    Display version and exit.

    Example
    $ java -jar ./mapp-intelligence-java-cronjob.jar -i 111111111111111 -d analytics01.wt-eu02.net -f /tmp/ -p MappIntelligenceData
     
    $ java -jar ./mapp-intelligence-java-cronjob.jar -i 111111111111111 -d analytics01.wt-eu02.net -f /tmp/ -p MappIntelligenceData --debug
     
     
    $ java -jar ./mapp-intelligence-java-cronjob.jar -c /path/to/your/configuration/file/config.properties
     
    $ java -jar ./mapp-intelligence-java-cronjob.jar -c /path/to/your/configuration/file/config.properties --debug

    Define a Cron Job

    To create your crontab file, type the following command at the shell prompt crontab -e and add the following lines:

    # sends every five minutes the tracking data to the Mapp tracking serve
    */5 * * * * java -jar ./mapp-intelligence-java-cronjob.jar -c /path/to/your/configuration/file/config.properties


    Was this article helpful?

    What's Next