hashicorp / nomad

Nomad is an easy-to-use, flexible, and performant workload orchestrator that can deploy a mix of microservice, batch, containerized, and non-containerized applications. Nomad is easy to operate and scale and has native Consul and Vault integrations.
https://www.nomadproject.io/
Other
14.78k stars 1.94k forks source link

Scheduled *Service* jobs #2395

Open Daviey opened 7 years ago

Daviey commented 7 years ago

I'd like to be able to run Service jobs on a schedule. These differ from Periodic Batch jobs as they do not have an inbuilt end-state. A good example of this would be running a webserver (such as Apache) between the hours of 9:00-5:00 Monday-Friday.

The two workarounds I can currently think of are:

I'd like to see a Time Scheduler in the Service job spec, but I i'm struggling to think of a way to express it.. Perhaps following cron standard:

simple start / stop:

job "docs" {
  scheduled {
    # only run from 9:00am Monday through to 17:00 Friday
    start = ["0 9 * * MON"]
    end   = ["0 17 * * FRI"]
  }
}

Specific hours on days:

job "docs" {
  scheduled {
    # only run on 09:00->17:00 between Monday and Friday
    start = ["0 9 * * MON-FRI"]
    end   = ["0 17 * * MON-FRI"]
  }
}

Limited days, fixed hours:

job "docs" {
  scheduled {
    # only run on 09:00->17:00 between Monday, Wednesday and Friday
    start = ["0 9 * * MON,WED,FRI"]
    end   = ["0 17 * * MON,WED,FRI"]
  }
}

multi-day different times (might be a bit of a reach!):

job "docs" {
  scheduled {
    # only run on Monday, Wednesday and Friday between different hours
    start = ["0 9 * * MON", "0 10 * * WED", "0 11 * * FRI"]
    end   = ["0 17 * * MON", "0 16 * * WED", "0 17 * * FRI"]
  }
}
kak-tus commented 7 years ago

Duplicate #1944

Daviey commented 7 years ago

I'm not quite sure I agree that it is a duplicate, but it is certainly linked. The other issue (#1944) is specifically for System jobs.. this is for scheduled Service jobs.

stevenscg commented 7 years ago

@Daviey I don't have this use-case right now, but it seems very interesting. What kinds of problems is it meant to address? I could see a fit for dev or test environments that you want to tear down after-hours or on weekends.

redi-walkerd commented 7 years ago

@stevenscg At the moment (pre-docker and Nomad), I have lots of cron jobs for starting and killing applications outside of business hours.. I'd like to get away from this... but it is currently really hard to model with Nomad without hacking/fudging it with the description I outlined.

In addition, I could see a use-case for different teams (different apps) having reserved resources between certain hours to make better use of resources.

dadgar commented 7 years ago

@redi-walkerd For now I would probably just run a cron that ups/downs the count of the job during the hours you need

KZachariassen commented 6 years ago

We would like this as well. It would be grate if nomad could cron schedule a docker image, so we dont need to build cron into all our images.

simon-graham commented 6 years ago

We also have a large number of services that should only be run during business hours. During business hours we'd want to retain existing nomad service capabilities such as restarting on task failure, but outside of business hours the service should be prevented from running. Speaking of business hours, a business calendar would also be extremely useful, so we can prevent batch jobs and services from running on holidays. However that's a whole separate issue. I mention it here because it may impact how a feature like this is implemented.

danbst commented 6 years ago

@dadgar

For now I would probably just run a cron that ups/downs the count of the job during the hours you need

When using .hcl Nomadfiles - should I do those changes with sed on Nomadfiles? Or there is better alternative?

ctc-santanaa commented 3 years ago

We're also interested in this functionality. Scheduling business hours would be a huge plus for systems that connect to outside services that have defined maintenance systems, like financial exchange gateways.

neomantra commented 2 years ago

Noting that the Nomad Autoscaler has an issue which would cover this use case: https://github.com/hashicorp/nomad-autoscaler/issues/448

There's no code in that issue, but there's a reference to a custom plugin repo with a "cron" scheduler: https://github.com/jsiebens/nomad-autoscaler-plugins

charnz commented 2 years ago

We are also looking for such a solution as it is a potential snag in our migration to Nomad. Our use case is similar to @ctc-santanaa operating in a financial services context where there is a well defined "end of day" which can vary per application and region. I have come across some work-arounds but all create a barrier to entry for us to migrate our existing jobs.

sebcoetzee commented 2 years ago

Can confirm that this would be a very useful feature for our use-case: trading applications that are only required to be up and running during market hours.

miketzian commented 1 year ago

This is for sure a missing feature. Being able to plugin different calendars/periodic configs (ala airflow timetable) would make this a lot more useful for batch use cases vs other legacy competitors