/** @ignore */
const Job = require('./Job');
/** @ignore */
const request = require('request');

class GithubChangeJob extends Job {

    /**
     * This method determines when the job should be execcuted.
     * 
     * @param  {RecurrenceRule} rule  A node-schedule CRON recurrence rule instance
     * @return {mixed}
     */
    runCondition(rule) {
        return '*/15 * * * *';
    }

    /**
     * The jobs main logic method, this method is executed 
     * whenever the {#runCondition()} method returns true.
     * 
     * @override
     */
    run() {
        request({
            headers: { 'User-Agent': 'AvaIre-Discord-Bot' },
            url: 'https://api.github.com/repos/senither/AvaIre/commits',
            method: 'GET'
        }, function (error, response, body) {

            if (!error && response.statusCode === 200) {
                try {
                    let parsed = JSON.parse(body);
                    
                    app.cache.forever('github.commits', parsed);
                } catch (e) {
                    app.logger.error('Github Changes job: The API returned an unconventional response.');
                    app.logger.error(e);
                }
            }
        })
    }
}

module.exports = GithubChangeJob;

/** @ignore */
const Job = require('./Job');
/** @ignore */
const request = require('request');

/**
 * Github change job, this job runs once an hour, every cycle 
 * the job will fetch the latest commits from the public 
 * github repository and store them in the file cache.
 *
 * @extends {Job}
 */
class GithubChangeJob extends Job {

    /**
     * The jobs constructor, this will check if the cache 
     * already exists, if it doesn't it will create 
     * it by calling the run method.
     */
    constructor() {
        super();

        if (! app.cache.has('github.commits')) {
            this.run();
        }
    }

    /**
     * This method determines when the job should be execcuted.
     * 
     * @param  {RecurrenceRule} rule  A node-schedule CRON recurrence rule instance
     * @return {mixed}
     */
    runCondition(rule) {
        return '0 * * * *';
    }

    /**
     * The jobs main logic method, this method is executed 
     * whenever the {#runCondition()} method returns true.
     * 
     * @override
     */
    run() {
        request({
            headers: { 'User-Agent': 'AvaIre-Discord-Bot' },
            url: 'https://api.github.com/repos/senither/AvaIre/commits',
            method: 'GET'
        }, function (error, response, body) {
            if (! error && response.statusCode === 200) {
                try {
                    let parsed = JSON.parse(body);
                    
                    app.cache.forever('github.commits', parsed);
                } catch (e) {
                    app.logger.error('Github Changes job: The API returned an unconventional response.');
                    app.logger.error(e);
                }
            }
        })
    }
}

module.exports = GithubChangeJob;

Add esdoc documentation and change the github change job to run once an hour
Add esdoc documentation and change the github change job to run once an hour
