public string CreateTask(
        string projectId = "YOUR-PROJECT-ID",
        string location  = "us-central1",
        string queue     = "my-queue",
        string url       = "http://example.com",
        string payload   = "Hello World!",
        int inSeconds    = 0)
    {
        CloudTasksClient client = CloudTasksClient.Create();
        QueueName        parent = new QueueName(projectId, location, queue);

        var response = client.CreateTask(new CreateTaskRequest
        {
            Parent = parent.ToString(),
            Task   = new Task
            {
                HttpRequest = new HttpRequest
                {
                    HttpMethod = HttpMethod.Post,
                    Url        = url,
                    Body       = ByteString.CopyFromUtf8(payload)
                },
                ScheduleTime = Timestamp.FromDateTime(
                    DateTime.UtcNow.AddSeconds(inSeconds))
            }
        });

        Console.WriteLine($"Created Task {response.Name}");
        return(response.Name);
    }
Ejemplo n.º 2
0
 public GCloudContentScanTaskService(IOptionsMonitor <GoogleTasksConfiguration> optionsMonitor, CloudTasksClient cloudTasksClient,
                                     IOptionsMonitor <ServerConfiguration> serverConfigurationOptionsMonitor)
 {
     this.googleTasksConfiguration = optionsMonitor.CurrentValue;
     this.cloudTasksClient         = cloudTasksClient;
     this.serverConfiguration      = serverConfigurationOptionsMonitor.CurrentValue;
 }
Ejemplo n.º 3
0
        // Method to put a message on a queue
        // Could be expanded to include message attributes, etc., in a SendMessageRequest
        public async Task <string> SendMessage(string messageBody)
        {
            //Console.WriteLine($"Send message to queue\n  {Configuration.GetValue<string>("sqsqueue")}");
            Console.WriteLine($"Send message to queue\n  {Configuration.GetValue<string>("gqueue")}");
            var projectId = Configuration.GetValue <string>("projectid");
            var location  = Configuration.GetValue <string>("location");
            var queue     = Configuration.GetValue <string>("gqueue");

            Console.WriteLine(messageBody);

            CloudTasksClient client = CloudTasksClient.Create();
            QueueName        parent = new QueueName(projectId, location, queue);

            var response = client.CreateTask(new CreateTaskRequest
            {
                Parent = parent.ToString(),
                Task   = new Google.Cloud.Tasks.V2.Task
                {
                    AppEngineHttpRequest = new AppEngineHttpRequest
                    {
                        HttpMethod  = HttpMethod.Post,
                        RelativeUri = "/sendtransaction",
                        Body        = ByteString.CopyFromUtf8(messageBody),
                    },
                    ScheduleTime = Timestamp.FromDateTime(
                        DateTime.UtcNow.AddSeconds(5))
                }
            });

            Console.WriteLine($"Created Task {response.Name}");
            return(response.Name);
        }
        public static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Error: please specify a project ID");
                return(1);
            }
            string projectId = args[0];
            string location  = Environment.GetEnvironmentVariable(LocationEnvironmentVariable);

            if (string.IsNullOrEmpty(location))
            {
                Console.WriteLine($"Error: please specify a project location in {LocationEnvironmentVariable} environment variable");
                return(1);
            }

            LocationName locationName = LocationName.FromProjectLocation(args[0], location);

            // Create client
            CloudTasksClient client = CloudTasksClient.Create();
            var queues = client.ListQueues(locationName);

            foreach (var queue in queues)
            {
                Console.WriteLine(queue.Name);
            }
            Console.WriteLine("Smoke test passed OK");
            return(0);
        }
Ejemplo n.º 5
0
        // [START cloud_tasks_appengine_create_task]
        public static object CreateTask(
            string projectId,
            string location,
            string queue,
            string payload,
            int inSeconds)
        {
            CloudTasksClient client = CloudTasksClient.Create();

            QueueName parent = new QueueName(projectId, location, queue);

            var unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            var response = client.CreateTask(new CreateTaskRequest
            {
                Parent = parent.ToString(),
                Task   = new Task
                {
                    AppEngineHttpRequest = new AppEngineHttpRequest
                    {
                        HttpMethod  = HttpMethod.Post,
                        RelativeUri = "/log_payload",
                        Body        = ByteString.CopyFromUtf8(payload)
                    },
                    ScheduleTime = new Timestamp
                    {
                        Seconds = (long)(DateTime.Now.AddSeconds(inSeconds) - unixEpoch).TotalSeconds,
                        Nanos   = 0
                    }
                }
            });

            Console.WriteLine($"Created Task {response.Name}");

            return(0);
        }