How to reliably schedule regularly reoccurring jobs with arangodb?

192 views Asked by At

I am evaluating arangodb "Community Edition" v.3.7.6 in Cluster Mode. At the moment, I am trying to figure out, how to reliably schedule regularly reoccurring jobs via queues in my foxx service. I have read the documentation pages here and here and came up with the following scripts:

setup.js

const queues = require('@arangodb/foxx/queues')

var myQueue = undefined
try {
    myQueue = queues.get('myqueue')
} catch (e) {
    myQueue = queues.create('myqueue')
}

myQueue.push({
    name: "myRegularTask",
    mount: module.context.mount
},
{to: '[email protected]', body: 'Hello world'},
{
  repeatTimes: Infinity,
  repeatUntil: Date.now() + (24 * 60 * 60 * 1000),
  repeatDelay: 5 * 1000
});

myRegularTask.js

'use strict';

const db = require('@arangodb').db;

const testCollection = db._collection('test')

testCollection.save({text: 'sample text'});

manifest.json

{
  "$schema": "http://json.schemastore.org/foxx-manifest",
  "main": "index.js",
  "engines": {
    "arangodb": "^3.0.0"
  },
  "name": "myapp",
  "version": "0.1.0",
  "tests": "test/**/*.js",
  "scripts": {
    "setup": "scripts/setup.js",
    "myRegularTask": "scripts/myRegularTask.js"
  }
}

So what I think it is supposed to do is that it registers a regular job that is executed every 5 seconds (and inserts a document into my testCollection) once I have installed my foxx service. It actually does that sometimes. However, most of the time nothing happens, no matter how long I wait.

And that is the question of this post: How come that the behavior of above code is undeterministic to me? What am I doing wrong to get it working always?

Thanks Seb

0

There are 0 answers