Skip to content

Cron like daemon process that runs executable based on messages received from pubsub subscription.

License

Notifications You must be signed in to change notification settings

tpokki/pubsub-execd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pubsub-execd

Cron like daemon process that triggers executables based on messages received from pubsub topic.

Configuration

Define the triggers in configuration file.

logging:
  output: stdout
triggers:
  - name: echo stuff
    run:
      timeout: 1h
      concurrency: 1
      exec: /bin/echo
      args:
        expression: {{ .Attributes.foobar }} {{ .Payload.foo.bar }}
    pubsub:
      project: sample123
      subscription: execd
  - name: date with format
    run:
      timeout: 20s
      concurrency: 1
      exec: date
      args:
        expression: +{{ .Attributes.format }}
    pubsub:
      project: sample123
      subscription: execd

logging spec:

  • output - define the log output, accepted values are none, syslog, stdout and stderr. Default is stdout.

run spec:

  • timeout - if the message is not ack in this time, it will be redelivered to subscription
  • concurrency - for receiving and processing messages for same trigger in parallel
  • exec - executable
  • args.expression - go-template to parse the received message. The attributes are stored as .Attributes and if the received data is in json format, it is stored in .Payload.

pubsub spec:

  • project - project id from where subscription should be found
  • subscription - subscription name

n.b pubsub-execd does not create subscriptions, and they must exist before using them in configuration.

Running

pubsub-execd -f /path/to/config.yaml

Example

  1. Setup topic execd-demo-topic with subscription exec-demo-sub in your project.
  2. Start the daemon:
pubsub-execd -f sample.yaml
  1. Send message to topic:
gcloud pubsub topics publish \
    --project=sample-project-123 execd-demo-topic \
    --message='{"foo": {"bar": "and-this" }, "foobar": "not printed"}' \
    --attribute=foobar=print-this,not=printed
  1. Expected output from daemon process:
2025/01/27 09:08:26 Running command: /bin/echo print-this and-this
print-this and-this
2025/01/27 09:08:26 Command /bin/echo executed successfully

About

Cron like daemon process that runs executable based on messages received from pubsub subscription.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published