Skip to content

Commit

Permalink
Merge pull request #25 from k2tzumi/expose-consume-job
Browse files Browse the repository at this point in the history
Expose consumeJob
  • Loading branch information
k2tzumi authored Mar 5, 2023
2 parents 42afa53 + f9f27d3 commit f05a5e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ declare namespace AppsScriptJobqueue {
/**
* Set the following function objects globally in your application that uses JobBroker
* ex)
* const jobEventHandler = JobBroker.jobEventHandler;
* const jobEventHandler = JobBroker.consumeJob;
*/
jobEventHandler: (event: TimeBasedEvent) => void;
consumeJob: (event: TimeBasedEvent) => void;
}

interface _JobBroker<T extends Parameter> {
Expand Down
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ declare const global: {

/**
* handler to execute the job.
* @param event Time-based event
* @param {TimeBasedEvent} event Time-based event
*/
const jobEventHandler = (event: TimeBasedEvent): void => {
new JobBroker<object>(jobEventHandler).consumeJob(event);
const func = global.consumeJob as (event: TimeBasedEvent) => void;
func(event);
};

global.jobEventHandler = jobEventHandler;
Expand All @@ -35,3 +36,11 @@ global.enqueueAsyncJob = (
global.createDelaydJob = (scheduled_at: Date): DelayedJobBroker<object> => {
return DelayedJobBroker.createJob<object>(jobEventHandler, scheduled_at);
};

/**
* Consume job
* @param {TimeBasedEvent} event Time-based event
*/
global.consumeJob = (event: TimeBasedEvent): void => {
new JobBroker<object>(jobEventHandler).consumeJob(event);
};

0 comments on commit f05a5e1

Please # to comment.