Skip to content

gaslamp


Class: TriggerArtisan

Advanced Google Apps Script trigger management with caching and logging.

TriggerArtisan provides efficient trigger operations with built-in logging via AfterGlow. It helps avoid duplicate triggers and manage their lifecycle by providing convenient methods to build and delete time-based triggers.

Remarks

  • Automatically deletes existing triggers before creating new ones to prevent duplicates
  • Supports daily and weekly trigger scheduling
  • Logs all operations for debugging and auditing
  • Thread-safe for use in Google Apps Script environment

Examples

Create a daily trigger:

TypeScript
const artisan = new TriggerArtisan({ name: "TriggerManager" });
artisan.buildDailyTrigger("myFunction", 14, 30, 1).create();

Create a weekly trigger:

TypeScript
const artisan = new TriggerArtisan();
artisan.buildWeeklyTrigger("myFunction", "mon", 1)?.create();

Since

0.1.0

Constructors

Constructor

new TriggerArtisan(options?): TriggerArtisan

Parameters

options?

TriggerArtisanOptions = {}

Returns

TriggerArtisan

Gaslets

getAfterGlow()

getAfterGlow(): AfterGlow

Get the internal AfterGlow logger instance for advanced usage.

Use this to access all logged operations or configure logging behavior.

Returns

AfterGlow

AfterGlow logger instance

Example

TypeScript
const artisan = new TriggerArtisan();
const logger = artisan.getAfterGlow();
const logs = logger.toMap();

Since

0.1.0


listProjectTriggers()

listProjectTriggers(): Map\<string, string>[] | null

List all triggers related to the current project.

Returns an array of maps containing trigger properties including ID, handler function, event type, trigger source, and source ID.

Returns

Map\<string, string>[] | null

Trigger properties array, or null if no triggers found

Example

TypeScript
const artisan = new TriggerArtisan();
const triggers = artisan.listProjectTriggers();
if (triggers) {
  console.log(`Found ${triggers.length} triggers`);
}

Since

0.1.0


deleteTrigger()

deleteTrigger(fn): void

Delete a trigger by handler function name.

Searches for and removes all triggers matching the given function name.

Parameters

fn

string

Handler function name to delete triggers for

Returns

void

Example

TypeScript
const artisan = new TriggerArtisan();
artisan.deleteTrigger("myFunction");

Since

0.1.0


buildDailyTrigger()

buildDailyTrigger(fn, hh, mm, days?): ClockTriggerBuilder

Build a daily time-based trigger.

Creates a trigger that runs at a specific time every N days. Automatically deletes existing triggers for the same function to prevent duplicates.

Parameters

fn

string

Handler function name

hh

number

Hour of day (0-23)

mm

number

Minute of hour (0-59)

days?

number = 1

Interval in days (default: 1)

Returns

ClockTriggerBuilder

Clock trigger builder (call .create() to apply)

Example

TypeScript
const artisan = new TriggerArtisan();
artisan.buildDailyTrigger("myFunction", 14, 30, 1).create();

Since

0.1.0


buildWeeklyTrigger()

buildWeeklyTrigger(fn, day, weeks?): ClockTriggerBuilder | null

Build a weekly time-based trigger.

Creates a trigger that runs on a specific day of the week every N weeks. Automatically deletes existing triggers for the same function to prevent duplicates.

Parameters

fn

string

Handler function name

day

string

Day abbreviation: "mon", "tue", "wed", "thu", "fri", "sat", "sun"

weeks?

number = 1

Interval in weeks (default: 1)

Returns

ClockTriggerBuilder | null

Clock trigger builder (call .create() to apply), or null if day is invalid

Example

TypeScript
const artisan = new TriggerArtisan();
artisan.buildWeeklyTrigger("myFunction", "mon", 1)?.create();

Since

0.1.0

Other

defaultName

readonly static defaultName: "TriggerArtisan" = "TriggerArtisan"