diff --git a/package.json b/package.json index 0c77a70..4e0ea5f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "croncat", - "version": "1.6.5", + "version": "1.7.0", "description": "cron.cat CLI and Agent Runner", "main": "src/index.js", "scripts": { diff --git a/src/agent.js b/src/agent.js index 4455b61..c3f7944 100644 --- a/src/agent.js +++ b/src/agent.js @@ -127,6 +127,10 @@ export const currentStatus = () => { return agentSettings.status || 'Pending' } +export const settings = () => { + return agentSettings || {} +} + // returns if agent is active or not export const checkStatus = async () => { let isActive = false diff --git a/src/tasks.js b/src/tasks.js index 8dd6f65..6777528 100644 --- a/src/tasks.js +++ b/src/tasks.js @@ -59,17 +59,20 @@ export const proxyCall = async () => { return skipThisIteration } +let agentSettings = {} export async function run() { let skipThisIteration = false + let previousAgentSettings = { ...agentSettings } + agentSettings = agent.settings() // 1. Check for tasks skipThisIteration = await getTasks() - if (skipThisIteration) return setTimeout(run, config.WAIT_INTERVAL_MS) - // 2. Check agent status - // TODO: Change - to only check if KICKED, needs to store local agent state - // skipThisIteration = await checkAgent() - // if (skipThisIteration) return setTimeout(run, config.WAIT_INTERVAL_MS) + // 2. Check agent kicked, if so, stop the loop until auto-reregister kicks in + if ( + previousAgentSettings && previousAgentSettings.status === 'Active' && + agentSettings && !agentSettings.status + ) skipThisIteration = true // 3. Sign task and submit to chain if (!skipThisIteration) skipThisIteration = await proxyCall() diff --git a/src/util.js b/src/util.js index 095882d..d8ff7aa 100644 --- a/src/util.js +++ b/src/util.js @@ -93,7 +93,6 @@ let cronManager = null export async function connect(options) { try { - // TODO: options await Near.getNearConnection(options) } catch (e) { log(`${chalk.red('NEAR Connection Failed')}`)