{"id":20980531,"url":"https://github.com/hyperjumptech/firebase-cronjob","last_synced_at":"2025-05-14T15:30:43.931Z","repository":{"id":102269512,"uuid":"256913639","full_name":"hyperjumptech/firebase-cronjob","owner":"hyperjumptech","description":"Cronjob building block for Firebase","archived":false,"fork":false,"pushed_at":"2020-10-19T23:10:27.000Z","size":237,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-02T20:04:59.375Z","etag":null,"topics":["cloud-scheduler","cronjob","firebase","firebase-functions","indonesia","serverless"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hyperjumptech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCTS.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-19T04:27:28.000Z","updated_at":"2025-03-07T22:10:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"6d36fb92-6aca-41c1-a9a6-8b487523fdd7","html_url":"https://github.com/hyperjumptech/firebase-cronjob","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjumptech%2Ffirebase-cronjob","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjumptech%2Ffirebase-cronjob/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjumptech%2Ffirebase-cronjob/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjumptech%2Ffirebase-cronjob/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyperjumptech","download_url":"https://codeload.github.com/hyperjumptech/firebase-cronjob/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254171566,"owners_count":22026464,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloud-scheduler","cronjob","firebase","firebase-functions","indonesia","serverless"],"created_at":"2024-11-19T05:29:02.674Z","updated_at":"2025-05-14T15:30:43.919Z","avatar_url":"https://github.com/hyperjumptech.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cronjob for Firebase\n\n![Continous Integration](https://github.com/hyperjumptech/firebase-cronjob/workflows/Continous%20Integration/badge.svg)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n## Principle of Operation\n\nUsing the [Scheduled functions feature](https://firebase.google.com/docs/functions/schedule-functions), the function `autoIncrementJobCounter` gets executed _once every minute_. This function does a very simple thing, i.e. it increments the value of `jobConfig/counter` in the Firestore database.\n\nIn addition, using the [Cloudstore triggers feature](https://firebase.google.com/docs/functions/firestore-events), another function, `generateQueues`, gets executed whenever the above counter is changed (effectively, also executed once per minute). This function iterates through all the entries in job configuration collection, `jobConfig` in the Firestore database, and check the corresponding `period` of each job config. If the modulus of the `counter` by the `period` is `0`, then a new queue is created in the `jobQueues` collection.\n\nNote that each job config must have at least _two_ mandatory properties: `task` and `period`, describing the type of task to be carried out and the period (in minutes) to schedule the task, respectively. Practically, a job config also has an `input` property which can store the input data for the corresponding task.\n\nWith same trigger on the `jobQueues` collection, each new queue will invoke the `runJob` function. This is where the actual work takes place. In this sample implementation, there is only one type of job (defined by its `task` property): to convert all the letters in a string to uppercase. Once the job is completed, a new run is created in the `jobRuns` collection.\n\nEach job run will have the following properties:\n* `jobId`: the unique string associated with the job config\n* `timestamp`: the starting time right before the execution (Unix epoch)\n* `elapsed`: the duration of the task execution (in milliseconds)\n* `result`: the output of executing the task\n\n## Setup\n\nRequirement: Node.js v10 or later.\n\nAfter repository clone, run `npm install`.\n\n### Firebase Project\n\nCreate a new project from [Firebase Console](https://console.firebase.google.com).\n\nFrom Firebase Console, _Update_ the project from Spark to Blaze (this requires payment information) as this is necessary to make scheduled Cloud Function working properly.\n\nGo to _Project Overview_ and then click on the `\u003c/\u003e` icon. Enter the nickname under _Register app_. Make sure to check the box _Also set up Firebase Hosting_.\n\nFrom Firebase Console, go to _Database_ and proceed to setup the Firestore database. Use the _Production_ security rules right away.\n\n### Quick Check\n\nDeploy the Firebase project as usual.\n\nTo quickly check that it is working, trigger the `ping` cloud function, e.g. by opening the URL in a web browser, such as `YOURFIREBASEPROJECT.firebaseapp.com/ping` and it should display `OK` following by the timestamp (Unix epoch).\n\n### Local Testing\n\nRun the integration tests (which uses Firebase emulators):\n```\nnpm run firebase -- emulators:exec \"npm test\" --project YOURFIREBASEPROJECT\n```\nwhere `YOURFIREBASEPROJECT` is the name of the Firebase project.\n\n### Deployment from Azure Pipelines\n\nTo initiate deployment to Firebase from Azure Pipelines, first grab the deployment token:\n```\nnpm run firebase -- login:ci\n```\nCopy the value, set is as variable `FIREBASE_TOKEN` at Azure Pipelines, Pipelines, Edit button, Variables button.\n\nSet another variable the similar way, `FIREBASE_PROJECT`, with the name of the project (from Firebase Console).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperjumptech%2Ffirebase-cronjob","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperjumptech%2Ffirebase-cronjob","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperjumptech%2Ffirebase-cronjob/lists"}