Is there a way to schedule a cron job to run every...
# ask-community
c
Is there a way to schedule a cron job to run every 10 minutes from 8AM-3PM? I started running it mid-day until now, it all worked except 3PM
Copy code
schedule:
  cron: "*/10 08-14 * * 1-5"
  timezone: "America/Chicago"
  active: "{{ prefect.blocks.string.active-status }}"
I think if it was from 08-15 it will run all times during the 2PM hour
k
if I'm understanding correctly, you want every 10 minutes, 8am-3pm, inclusive
so a 3pm run happens, but not at 3:10pm
c
Correct
k
might be hard to do with a single cron expression, but deployments can now have multiple schedules
c
Yeah
k
so you could just add a second schedule that only does a 3pm run
c
Copy code
- name: Covered-Shares-Report
  description: Email sent every 10 minutes to alert traders of covered shares
  entrypoint: src/reports/covered_shares_report.py:covered_shares_report
  work_pool: *ny4_work_pool
  parameters: {
              recipients: []
  }
  schedule:
    cron: "*/10 08-14 * * 1-5"
    timezone: "America/Chicago"
    active: "{{ prefect.blocks.string.active-status }}"
  schedule:
    cron: "0 15 * * 1-5"
    timezone: "America/Chicago"
    active: "{{ prefect.blocks.string.active-status }}"
Like this?
k
I think it's
schedules
with a list of schedules
👍 1
Copy code
schedules:
- cron: "*/10 08-14 * * 1-5"
  timezone: "America/Chicago"
  active: "{{ prefect.blocks.string.active-status }}"
- cron: "0 15 * * 1-5"
  timezone: "America/Chicago"
  active: "{{ prefect.blocks.string.active-status }}"
👍 1
c
Thank you. I'll give that a try
Copy code
- name: Covered-Shares-Report
  description: Email sent every 10 minutes to alert traders of covered shares
  entrypoint: src/reports/covered_shares_report.py:covered_shares_report
  work_pool: *ny4_work_pool
  parameters: {
              recipients: []
  }
  schedules:
  - cron: "*/10 08-14 * * 1-5"
    timezone: "America/Chicago"
    active: "{{ prefect.blocks.string.active-status }}"
  - cron: "0 15 * * 1-5"
    timezone: "America/Chicago"
    active: "{{ prefect.blocks.string.active-status }}"
@Kevin Grismore I tried this, but it didn't appear to deploy the schedule
I tried this too.
Copy code
- name: Covered-Shares-Report
  description: Email sent every 10 minutes to alert traders of covered shares
  entrypoint: src/reports/covered_shares_report.py:covered_shares_report
  work_pool: *ny4_work_pool
  parameters: {
              recipients: []
  }
  schedules:
    - schedule:
      cron: "*/10 08-14 * * 1-5"
      timezone: "America/Chicago"
      active: "{{ prefect.blocks.string.active-status }}"
    - schedule:
      cron: "0 15 * * 1-5"
      timezone: "America/Chicago"
      active: "{{ prefect.blocks.string.active-status }}"
@Nate
k
I made a deployment like this:
Copy code
build:
push:
pull:

deployments:
- name: datalake-deployment
  entrypoint: datalake_listener.py:datalake_listener
  schedules:
  - cron: 0 0 * * *
    active: False
  - cron: 1 0 * * *
    active: False
  work_pool: 
    name: k8s-demo
and it does have both schedules on it
maybe your local install of prefect isn't up to date for recognizing multiple schedules?
👍 1
c
@Kevin Grismore It worked! Thank you for pointing that out.