Class: Zizq::CrontabEntryBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/zizq/crontab_entry_builder.rb,
sig/generated/zizq/crontab_entry_builder.rbs

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.

Parameters:

  • target (Zizq::Crontab)
  • name (String)
  • expression (String)
  • timezone: (String, nil) (defaults to: nil)
  • paused: (Boolean, nil) (defaults to: nil)


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

#callback^(Zizq::CrontabEntry) -> Zizq::CrontabEntry (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

#expressionString (readonly)

The cron expression for the entry.

Returns:

  • (String)


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

def expression
  @expression
end

#nameString (readonly)

The name of the entry being built.

Returns:

  • (String)


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

def name
  @name
end

#pausedBoolean? (readonly)

True if this entry will be paused.

Returns:

  • (Boolean, nil)


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

def paused
  @paused
end

#targetZizq::Crontab (readonly)

The Crontab instance onto which entries are applied.

Returns:



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

def target
  @target
end

#timezoneString? (readonly)

Optional timezone for the entry.

Defaults to the Zizq server timezone when not specified.

Returns:

  • (String, nil)


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) ⇒ void

This method returns an undefined value.

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

Parameters:



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 {|arg0| ... } ⇒ self

Bulk enqueues are not supported via cron.

Yields:

Yield Parameters:

Yield Returns:

  • (void)

Returns:

  • (self)


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) ⇒ void

This method returns an undefined value.

Process a raw job enqueue for this entry.

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

Parameters:

  • queue: (String)
  • type: (String)
  • payload: (Object)
  • opts (Object)


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) ⇒ EnqueueWith

Provide common fields to be used when enqueueing a job.

Parameters:

  • overrides (Object)

Returns:



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

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

#push_entry(req) ⇒ Object

Parameters:

  • req (Object)

Returns:

  • (Object)


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/zizq/crontab_entry_builder.rb', line 114

def push_entry(req)
  if req.ready_at || req.delay
    raise ArgumentError, 'delayed job are not permitted via cron'
  end

  entry = callback.call(
    CrontabEntry.new(
      target,
      name,
      expression,
      job: req,
      timezone:,
      paused:,
    ),
  )

  target.entries[entry.name] = entry
end