1

I have a function that I want to run every 8 seconds. but i am getting error while installing it. It loads when I change the seconds to "every 8 hours". it doesn't give any errors. Does firebase pubsub not accept times in seconds?

const otherMatchBotModule = require("./otherMatchBotActive");
exports.otherMatchBotActive = functions.pubsub.schedule("every 8 seconds").onRun(otherMatchBotModule.otherMatchBot);

console output:

i  functions: creating Node.js 14 function otherMatchBotActive(us-central1)...

Functions deploy had errors with the following functions:
        otherMatchBotActive(us-central1)
i  functions: cleaning up build files...

Error: There was an error deploying functions

log file details:

[debug] [2022-06-28T01:36:49.114Z] Error: Failed to upsert schedule function otherMatchBotActive in region us-central1
    at /Users/durak/.cache/firebase/tools/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:38:11
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Fabricator.upsertScheduleV1 (/Users/durak/.cache/firebase/tools/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:378:9)
    at async Fabricator.setTrigger (/Users/durak/.cache/firebase/tools/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:347:17)
    at async Fabricator.createEndpoint (/Users/durak/.cache/firebase/tools/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:124:9)
    at async handle (/Users/durak/.cache/firebase/tools/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:75:17)
[error] 
[error] Error: There was an error deploying functions
ursan526
  • 485
  • 3
  • 10

1 Answers1

2

functions.pubsub.schedule() uses Cloud Scheduler to schedule running a function. The smallest time granularity is 1 minute.

The following image shows the fields that will be translated from "every 8 seconds" to the Cron job format. Notice that there is no second field, therefore your request is invalid.

Cron job format

enter image description here

John Hanley
  • 74,467
  • 6
  • 95
  • 159
  • After running a function with another trigger, is there a way to wait 8 seconds and run another function? – ursan526 Jun 28 '22 at 02:00
  • @ursan526 - Please create a new post for each question. Do you mean something like **sleep for 8 seconds**? Your code can do anything it wants within the maximum function duration. You will pay for that sleep time. There are many possibilities, that is why you should create another question. – John Hanley Jun 28 '22 at 02:04
  • I explain my problem in detail in this link https://stackoverflow.com/questions/72780175/firebase-cloud-function-run-after-10-seconds – ursan526 Jun 28 '22 at 02:40