I have an app that pulls data from a workflow system, creates a table of qualifying records and sends an email containing the table to a group of people for downstream processing.
The issue is there is no event other than manually going to the URL the app is exposed on to trigger this.
So I thought to create a cron job that runs every 15mins. I have followed this guide (Crontab with Supercronic · Fly Docs) but get an error during fly deploy
==> Verifying app config
Validating C:\Users\tfmei\Documents\Projects\ready2invoice\fly.toml
Service specifies 'app' as one of its processes, but no processes are defined with that name; update fly.toml [processes] to add 'app' process or remove it from service's processes list
✘invalid app configuration
Error: App configuration is not valid
Here’s the updated fly.toml that generated the above message
Hi @camodue, it looks your fly.toml has defined a http service that runs the app process but it is not defined in the [processes] section. You should add the app process to the process group if you want to have both the http service and the cron running simultaneously.
[processes]
app = "bundle exec rails server -b [::] -p 8080" # or whatever starts your internet facing app
cron = "supercronic /app/crontab"
Ok I have some updates. The invalid app configuration error is gone but I’m not sure that supercronic and curl actually get installed.
Here’s the Dockerfile
FROM node:alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
#CMD ["node", "app.js"]
# Install necessary packages for curl
RUN apk update && apk install -y curl
# Install necessary packages for supercronic
RUN apk add --no-cache curl
# Latest releases available at https://github.com/aptible/supercronic/releases
ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.2.29/supercronic-linux-amd64 \
SUPERCRONIC=supercronic-linux-amd64 \
SUPERCRONIC_SHA1SUM=cd48d45c4b10f3f0bfdd3a57d054cd05ac96812b
RUN curl -fsSLO "$SUPERCRONIC_URL" \
&& echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \
&& chmod +x "$SUPERCRONIC" \
&& mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
&& ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic
# Copy the crontab file
COPY crontab /app/crontab
# Run the app and the cron process
CMD ["sh", "-c", "npm run start & supercronic /app/crontab"]
and the updated fly.toml
# fly.toml app configuration file generated for ready2invoice on 2024-03-14T11:54:26+11:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = 'ready2invoice'
primary_region = 'syd'
[experimental]
[build]
builder = "gcr.io/buildpacks/builder"
args = { target = "x86_64-unknown-linux-musl" }
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ['app']
[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
### Added to include crontab
[processes]
app = "npm run start" # command to start the Node.js app
cron = "supercronic /app/crontab"
[mounts]
source="storage_dir"
destination="/workspace/storage"
Partial output from fly deploy
✔ [1/2] Machine 91852306f50258 [app] update succeeded
✖ [2/2] Machine 6e824271f31558 [cron] update failed: smoke checks for 6e824271f31558 failed: the app appears to be c…
-------
Checking DNS configuration for ready2invoice.fly.dev
Error: smoke checks for 6e824271f31558 failed: the app appears to be crashing
Stacktrace:
goroutine 1 [running]:
runtime/debug.Stack()
/opt/hostedtoolcache/go/1.21.7/x64/src/runtime/debug/stack.go:24 +0x5e
github.com/superfly/flyctl/internal/cli.printError(0xc0004daaa0, 0xc0013e7b3e, 0x264ba60?, {0x2e8f200, 0xc00111cb40})
/home/runner/work/flyctl/flyctl/internal/cli/cli.go:162 +0x4db
github.com/superfly/flyctl/internal/cli.Run({0x2eac180?, 0xc000875140?}, 0xc0004daaa0, {0xc000140090?, 0x2, 0x3})
/home/runner/work/flyctl/flyctl/internal/cli/cli.go:110 +0x928
main.run()
/home/runner/work/flyctl/flyctl/main.go:47 +0x156
main.main()
/home/runner/work/flyctl/flyctl/main.go:26 +0x18
C:\Users\tfmei\Documents\Projects\ready2invoice>
Based on the log it can’t find supercronic
INFO Starting init (commit: 5b8fb02)...
INFO Preparing to run: `launcher supercronic /app/crontab` as cnb
INFO [fly api proxy] listening at /.fly/api
2024/04/09 22:47:38 listening on [fdaa:2:f5a2:a7b:243:abb8:a64a:2]:22 (DNS: [fdaa::3]:53)
Machine started in 439ms
supercronic: line 1: supercronic: command not found
INFO Main child exited normally with code: 127
INFO Starting clean up.
machine did not have a restart policy, defaulting to restart
Can you try passing the full path to supercronic in your fly.toml?
[processes]
app = "npm run start" # command to start the Node.js app
cron = "/usr/local/bin/supercronic /app/crontab"
Also, you seem to be installing curl twice. You just need apk add curl.
If you want to debug further, one thing you can try is to run a new machine using the latest image (which should be in your fly deploy output) and open up a shell: