Class: Ductr::RufusTrigger

Inherits:
Trigger
  • Object
show all
Defined in:
lib/ductr/rufus_trigger.rb

Overview

A time related trigger, used to trigger jobs or pipelines based on temporal events. The trigger is registered as ‘:schedule`:

trigger :schedule, every: "1min"
def every_minute
  MyPipeline.perform_later
end

This trigger is based on the ‘rufus-scheduler` gem. Under the hood, the internal method `Rufus::Scheduler#do_schedule` is used.

There are 4 types of options available:

  • ‘:once`, used to schedule at a given time

    trigger :schedule, once: “10d” # Will run in ten days trigger :schedule, once: “2042/12/12 23:59:00” # Will run at the given date

  • ‘:every`, triggers following the given frequency

    trigger :schedule, every: “1min” # will run every minute.

  • ‘:interval`, run the trigger then waits the given interval before running again

    # Will run every 4 + 1 seconds trigger :schedule, interval: “4s” def every_interval

    sleep(1)
    MyPipeline.perform_later
    

    end

  • ‘:cron`, run the trigger following the given crontab pattern

    trigger :schedule, cron: “00 01 * * *” # Will run every day at 1am.

Direct Known Subclasses

SequelBase::PollingTrigger

Instance Attribute Summary

Attributes inherited from Trigger

#adapter

Instance Method Summary collapse

Methods inherited from Trigger

#initialize, #start

Constructor Details

This class inherits a constructor from Ductr::Trigger

Instance Method Details

#add(method, options) ⇒ void

This method returns an undefined value.

Adds a new trigger into rufus-scheduler.

Parameters:

  • method (Symbol)

    The scheduler method to be called by rufus-scheduler

  • options (Hash<Symbol: String>)

    The options to configure rufus-scheduler



53
54
55
56
57
58
59
# File 'lib/ductr/rufus_trigger.rb', line 53

def add(method, options)
  rufus_type = options.keys.first
  rufus_value = options.values.first
  handler = callable(method, **options)

  do_schedule(rufus_type, rufus_value, handler)
end

#stopvoid

This method returns an undefined value.

Shutdown rufus-scheduler



66
67
68
# File 'lib/ductr/rufus_trigger.rb', line 66

def stop
  rufus.shutdown
end