Files
nomad/ui/app/models/task-state.js
Daniel Bennett 4415fabe7d jobspec: time based task execution (#22201)
this is the CE side of an Enterprise-only feature.
a job trying to use this in CE will fail to validate.

to enable daily-scheduled execution entirely client-side,
a job may now contain:

task "name" {
  schedule {
    cron {
      start    = "0 12 * * * *" # may not include "," or "/"
      end      = "0 16"         # partial cron, with only {minute} {hour}
      timezone = "EST"          # anything in your tzdb
    }
  }
...

and everything about the allocation will be placed as usual,
but if outside the specified schedule, the taskrunner will block
on the client, waiting on the schedule start, before proceeding
with the task driver execution, etc.

this includes a taksrunner hook, which watches for the end of
the schedule, at which point it will kill the task.

then, restarts-allowing, a new task will start and again block
waiting for start, and so on.

this also includes all the plumbing required to pipe API calls
through from command->api->agent->server->client, so that
tasks can be force-run, force-paused, or resume the schedule
on demand.
2024-05-22 15:40:25 -05:00

87 lines
2.1 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { computed } from '@ember/object';
import { alias, and } from '@ember/object/computed';
import Fragment from 'ember-data-model-fragments/fragment';
import { attr } from '@ember-data/model';
import {
fragment,
fragmentOwner,
fragmentArray,
} from 'ember-data-model-fragments/attributes';
import classic from 'ember-classic-decorator';
@classic
export default class TaskState extends Fragment {
@fragmentOwner() allocation;
@attr('string') name;
@attr('string') state;
@attr('date') startedAt;
@attr('date') finishedAt;
@attr('boolean') failed;
@attr() paused;
@and('isActive', 'allocation.isRunning') isRunning;
@computed('task.kind')
get isConnectProxy() {
return (this.get('task.kind') || '').startsWith('connect-proxy:');
}
@computed('name', 'allocation.taskGroup.tasks.[]')
get task() {
const tasks = this.get('allocation.taskGroup.tasks');
return tasks && tasks.findBy('name', this.name);
}
@alias('task.driver') driver;
// TaskState represents a task running on a node, so in addition to knowing the
// driver via the task, the health of the driver is also known via the node
@computed('task.driver', 'allocation.node.drivers.[]')
get driverStatus() {
const nodeDrivers = this.get('allocation.node.drivers') || [];
return nodeDrivers.findBy('name', this.get('task.driver'));
}
@fragment('resources') resources;
@fragmentArray('task-event') events;
@computed('state')
get stateClass() {
const classMap = {
pending: 'is-pending',
running: 'is-primary',
finished: 'is-complete',
failed: 'is-error',
};
return classMap[this.state] || 'is-dark';
}
@computed('state')
get isActive() {
return this.state === 'running';
}
restart() {
return this.allocation.restart(this.name);
}
forcePause() {
return this.allocation.forcePause(this.name);
}
forceRun() {
return this.allocation.forceRun(this.name);
}
reEnableSchedule() {
return this.allocation.reEnableSchedule(this.name);
}
}