breejs / bree

Bree is a Node.js and JavaScript job task scheduler with worker threads, cron, Date, and human syntax. Built for @ladjs, @forwardemail, @spamscanner, @cabinjs.
https://jobscheduler.net
MIT License
2.96k stars 80 forks source link

[fix] Types aren't making timeout and interval optional #221

Closed EphraimB closed 1 year ago

EphraimB commented 1 year ago

Describe the bug

Node.js version: 19

OS version: Windows 11

Description: I'm using Bree with cron and can't be mixed with an interval. You need to make interval and timeout optional.

Actual behavior

Type '{ name: string; cron: string; path: string; worker: { workerData: { account_id: number; amount: number; description: string; }; }; }' is missing the following properties from type 'Job': timeout, interval

Expected behavior

Error shouldn't be there

Code to reproduce

/**
 * 
 * @param payrollData - Payroll data
 * @param account_id - The account_id of the employee
 * @param filePath - Path to the cron job file
 * @param jobsFilePath - Path to the jobs.json file
 * @returns - New job
 */
const schedulePayrollCronJob = async (payrollData: PayrollData, account_id: number, filePath: string | null, jobsFilePath: string | null): Promise<Job> => {
    const jobs = [];
    jobsFilePath = jobsFilePath || path.join(__dirname, '../jobs.json');
    const { end_date, net_pay } = payrollData;

    const uniqueId: string = createUniqueId();

    try {
        filePath = filePath || path.join(__dirname, 'cron-jobs', `${uniqueId}.js`);
        fs.closeSync(fs.openSync(filePath, 'w'));
    } catch (err) {
        console.error(err);
    }

    const newJob = createNewJob(uniqueId, end_date, account_id, net_pay);
    jobs.push(newJob);

    try {
        return newJob;
    } catch (error) {
        console.error('Error while scheduling job:', error);
        throw error;
    }
};

export default schedulePayrollCronJob;

We encourage you to submit a pull request with a failing test:

1) This will make it more likely for us to prioritize your issue. 2) It's a good way to prove that the issue is related to this project and not your code.

Example: https://github.com/avajs/ava/blob/master/docs/01-writing-tests.md#failing-tests -->

Checklist

shadowgate15 commented 1 year ago

You shouldn't be creating Job type, it should be JobOptions type. Job is used after Bree has processed the options and added it to the Bree object.

EphraimB commented 1 year ago

Thank you