121 lines
4.3 KiB
C
121 lines
4.3 KiB
C
/****************************************************************************
|
|
* <Novell-copyright>
|
|
* Copyright (c) 2001 Novell, Inc. All Rights Reserved.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of version 2 of the GNU General Public License
|
|
* as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, contact Novell, Inc.
|
|
*
|
|
* To contact Novell about this file by physical or electronic mail, you
|
|
* may find current contact information at www.novell.com.
|
|
* </Novell-copyright>
|
|
****************************************************************************/
|
|
|
|
#ifndef BONGO_SCHEDULER_H
|
|
#define BONGO_SCHEDULER_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define BONGO_SCHEDULER_NAME_SIZE 128
|
|
#define BONGO_SCHEDULER_ERROR_SIZE 512
|
|
|
|
typedef struct BongoScheduler BongoScheduler;
|
|
|
|
typedef struct BongoScheduledJobConfig {
|
|
const char *name;
|
|
int enabled;
|
|
int64_t interval_seconds;
|
|
int64_t jitter_seconds;
|
|
int64_t retry_initial_seconds;
|
|
int64_t retry_max_seconds;
|
|
} BongoScheduledJobConfig;
|
|
|
|
typedef struct BongoScheduledJobLease {
|
|
char name[BONGO_SCHEDULER_NAME_SIZE];
|
|
int64_t token;
|
|
int64_t interval_seconds;
|
|
int64_t jitter_seconds;
|
|
int64_t retry_initial_seconds;
|
|
int64_t retry_max_seconds;
|
|
} BongoScheduledJobLease;
|
|
|
|
typedef struct BongoScheduledJobStatus {
|
|
char name[BONGO_SCHEDULER_NAME_SIZE];
|
|
int enabled;
|
|
int running;
|
|
int requested;
|
|
int64_t next_run;
|
|
int64_t not_before;
|
|
int64_t last_started;
|
|
int64_t last_finished;
|
|
int64_t last_success;
|
|
int64_t consecutive_failures;
|
|
char last_error[BONGO_SCHEDULER_ERROR_SIZE];
|
|
} BongoScheduledJobStatus;
|
|
|
|
typedef int (*BongoSchedulerListCallback)(
|
|
const BongoScheduledJobStatus *status, void *data);
|
|
|
|
int BongoSchedulerOpen(BongoScheduler **scheduler, const char *database_path);
|
|
void BongoSchedulerClose(BongoScheduler **scheduler);
|
|
|
|
/* Synchronize the compiled/configured registry while preserving run history. */
|
|
int BongoSchedulerSync(BongoScheduler *scheduler,
|
|
const BongoScheduledJobConfig *jobs,
|
|
size_t job_count, int64_t now);
|
|
|
|
/* Mark jobs interrupted by a previous worker process as failed and retryable. */
|
|
int BongoSchedulerRecoverInterrupted(BongoScheduler *scheduler, int64_t now);
|
|
|
|
/* Atomically claim at most one due job. Returns 1, 0, or -1 on error. */
|
|
int BongoSchedulerClaimDue(BongoScheduler *scheduler, int64_t now,
|
|
BongoScheduledJobLease *lease);
|
|
|
|
/* Finish only the matching lease. Returns 1, 0 for stale lease, or -1. */
|
|
int BongoSchedulerFinish(BongoScheduler *scheduler,
|
|
const BongoScheduledJobLease *lease,
|
|
int success, const char *error, int64_t now);
|
|
|
|
/*
|
|
* As BongoSchedulerFinish(), but never schedules the next invocation before
|
|
* not_before. Successful jobs use an explicit future value as their exact
|
|
* next run time. Failed jobs retain exponential backoff and apply the later
|
|
* of backoff and not_before (for example an ACME Retry-After value).
|
|
*/
|
|
int BongoSchedulerFinishNotBefore(BongoScheduler *scheduler,
|
|
const BongoScheduledJobLease *lease,
|
|
int success, const char *error, int64_t now,
|
|
int64_t not_before);
|
|
|
|
/*
|
|
* Queue a run without allowing a second concurrent lease. A persisted
|
|
* provider/remote not-before boundary is never bypassed by this request.
|
|
*/
|
|
int BongoSchedulerRequest(BongoScheduler *scheduler, const char *name,
|
|
int64_t now);
|
|
|
|
int BongoSchedulerGetStatus(BongoScheduler *scheduler, const char *name,
|
|
BongoScheduledJobStatus *status);
|
|
int BongoSchedulerList(BongoScheduler *scheduler,
|
|
BongoSchedulerListCallback callback, void *data);
|
|
int BongoSchedulerNextRun(BongoScheduler *scheduler, int64_t *next_run);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|