Class: Zizq::CrontabEntryBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/zizq/crontab_entry_builder.rb

Overview

Builder class used to define individual entries within a Crontab schedule.

This is used internally by ‘Zizq.define_crontab`. See documentation for that method for full details.

Callers must call one of the enqueue methods to complete the build process.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, name, expression, timezone: nil, paused: nil, &block) ⇒ CrontabEntryBuilder

Initialize the builder with the given inputs.



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/zizq/crontab_entry_builder.rb', line 49

def initialize(target,
               name,
               expression,
               timezone: nil,
               paused: nil,
               &block)
  @target = target
  @name = name
  @expression = expression
  @timezone = timezone
  @paused = paused
  @callback = block || :itself.to_proc
end

Instance Attribute Details

#callbackObject (readonly)

Callback through which the built entry is passed before being added to the Crontab schedule.

The callback receives the Zizq::CrontabEntry instance and may return an alternative instance to be used after it has done any processing on the entry.



39
40
41
# File 'lib/zizq/crontab_entry_builder.rb', line 39

def callback
  @callback
end

#expressionObject (readonly)

The cron expression for the entry.



23
24
25
# File 'lib/zizq/crontab_entry_builder.rb', line 23

def expression
  @expression
end

#nameObject (readonly)

The name of the entry being built.



20
21
22
# File 'lib/zizq/crontab_entry_builder.rb', line 20

def name
  @name
end

#pausedObject (readonly)

True if this entry will be paused.



31
32
33
# File 'lib/zizq/crontab_entry_builder.rb', line 31

def paused
  @paused
end

#targetObject (readonly)

The Crontab instance onto which entries are applied.



17
18
19
# File 'lib/zizq/crontab_entry_builder.rb', line 17

def target
  @target
end

#timezoneObject (readonly)

Optional timezone for the entry.

Defaults to the Zizq server timezone when not specified.



28
29
30
# File 'lib/zizq/crontab_entry_builder.rb', line 28

def timezone
  @timezone
end

Instance Method Details

#enqueue(job_class, *args, **kwargs, &block) ⇒ Object

Enqueue a Zizq::Job or ActiveJob class using Zizq::ActiveJobConfig via this entry.



71
72
73
# File 'lib/zizq/crontab_entry_builder.rb', line 71

def enqueue(job_class, *args, **kwargs, &block)
  push_entry(Zizq.build_enqueue_request(job_class, *args, **kwargs, &block))
end

#enqueue_bulk(&block) ⇒ Object

Bulk enqueues are not supported via cron.

Raises:

  • (NotImplementedError)


98
99
100
# File 'lib/zizq/crontab_entry_builder.rb', line 98

def enqueue_bulk(&block)
  raise NotImplementedError, 'bulk enqueues are not supported via cron'
end

#enqueue_raw(queue:, type:, payload:, **opts) ⇒ Object

Process a raw job enqueue for this entry.

This is used for low-level or cross-language support.



90
91
92
# File 'lib/zizq/crontab_entry_builder.rb', line 90

def enqueue_raw(queue:, type:, payload:, **opts)
  push_entry(EnqueueRequest.new(queue:, type:, payload:, **opts))
end

#enqueue_with(**overrides) ⇒ Object

Provide common fields to be used when enqueueing a job.



106
107
108
# File 'lib/zizq/crontab_entry_builder.rb', line 106

def enqueue_with(**overrides)
  EnqueueWith.new(self, overrides)
end