Skip to content

Feature execute method#41

Open
mrosenlund wants to merge 2 commits into
antonsamper:masterfrom
mrosenlund:feature-execute-method
Open

Feature execute method#41
mrosenlund wants to merge 2 commits into
antonsamper:masterfrom
mrosenlund:feature-execute-method

Conversation

@mrosenlund

Copy link
Copy Markdown

Description

This pull request adds support for executing methods directly in cron jobs configured with the hapi-cron plugin.

Changes

  • Added an execute option to the job configuration, allowing users to specify a function to be executed at the scheduled time.
  • Modified internals.trigger to handle the execute option in addition to the existing request option.
  • Updated validation to ensure either job.request or job.execute is provided.

Example Usage

const server = Hapi.server({ port: 3000, host: 'localhost' });

const myFunction = async () => {
    console.log('myFunction was called!');
    return 'Function execution result';
};

await server.register({
    plugin: HapiCron,
    options: {
        jobs: [
            {
                name: 'myFunctionCron',
                time: '*/10 * * * * *', // every 10 seconds
                timezone: 'America/Vancouver',
                execute: myFunction,
                onComplete: (result) => {
                    console.log('Job completed with result:', result);
                }
            }
        ]
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant